diff options
author | hekeguang <hekeguang@chinamobile.com> | 2020-02-19 15:10:52 +0800 |
---|---|---|
committer | hekeguang <hekeguang@chinamobile.com> | 2020-02-19 15:11:55 +0800 |
commit | ee28e9071e114aba6d5d3a2eee4fb5b6f7247f14 (patch) | |
tree | cb1f7f491bbe404ad5a2c9104396f853aa92f325 | |
parent | a4d4f1680ffefc92a24a166234151a227fae4110 (diff) |
Add processing code related to slice task management
Issue-ID: USECASEUI-368
Change-Id: I668d06a1e5c1ea5b3466f526c8116f00bd0a21cd
Signed-off-by: hekeguang <hekeguang@chinamobile.com>
6 files changed, 876 insertions, 2 deletions
diff --git a/server/pom.xml b/server/pom.xml index f72cfb67..7a88c68f 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -231,7 +231,11 @@ <artifactId>okhttp</artifactId> <version>3.12.1</version> </dependency> - + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.9.4</version> + </dependency> <!-- commons-csv --> <dependency> <groupId>org.apache.commons</groupId> @@ -275,7 +279,11 @@ <artifactId>httpclient</artifactId> <version>4.5.4</version> </dependency> - + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.2.4</version> + </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/TaskMgtService.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/TaskMgtService.java new file mode 100644 index 00000000..253367df --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/TaskMgtService.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 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.service.nsmf; + +import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskAuditInfo; + +public interface TaskMgtService { + + ServiceResult querySlicingTask(int pageNo, int pageSize); + + ServiceResult querySlicingTaskByStatus(String processingStatus, int pageNo, int pageSize); + + ServiceResult queryTaskAuditInfo(String taskId); + + ServiceResult updateTaskAuditInfo(SlicingTaskAuditInfo slicingTaskAuditInfo); + + ServiceResult queryTaskCreationInfo(String taskId); + + ServiceResult queryTaskCreationProgress(String taskId); + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/GeneralConvertImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/GeneralConvertImpl.java new file mode 100644 index 00000000..df6c8be8 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/GeneralConvertImpl.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2019 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.service.nsmf.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant; +import org.onap.usecaseui.server.service.slicingdomain.aai.AAISliceService; +import org.onap.usecaseui.server.service.slicingdomain.aai.bean.AAIServiceAndInstance; +import org.onap.usecaseui.server.service.slicingdomain.aai.bean.Relationship; +import org.onap.usecaseui.server.service.slicingdomain.aai.bean.RelationshipData; +import org.onap.usecaseui.server.util.RestfulServices; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import retrofit2.Response; + +public class GeneralConvertImpl { + + private static final Logger logger = LoggerFactory.getLogger(GeneralConvertImpl.class); + private AAISliceService aaiSliceService; + + public GeneralConvertImpl() { + this(RestfulServices.create(AAISliceService.class)); + } + + public GeneralConvertImpl(AAISliceService aaiSliceService) { + this.aaiSliceService = aaiSliceService; + } + + public AAIServiceAndInstance queryServiceUtil(JSONObject object) { + if (object.containsKey("relationship-list")) { + AAIServiceAndInstance aaiServiceAndInstance = new AAIServiceAndInstance(); + aaiServiceAndInstance.setModelInvariantId(object.getString("model-invariant-id")); + aaiServiceAndInstance.setModelVersionId(object.getString("model-version-id")); + if (object.containsKey("workload-context")) { + aaiServiceAndInstance.setWorkloadContext(object.getString("workload-context")); + } + + JSONArray array = object.getJSONObject("relationship-list").getJSONArray("relationship"); + List<Relationship> relationshipList = new ArrayList<Relationship>(); + for (int i = 0; i < array.size(); i++) { + Relationship relationship = new Relationship(); + JSONObject objectShip = array.getJSONObject(i); + JSONArray arrayData = objectShip.getJSONArray("relationship-data"); + relationship.setRelatedTo(objectShip.getString("related-to")); + List<RelationshipData> RelationshipDataList = new ArrayList<RelationshipData>(); + for (int j = 0; j < arrayData.size(); j++) { + RelationshipData relationshipData = new RelationshipData(); + JSONObject objectData = arrayData.getJSONObject(j); + relationshipData.setRelationshipKey(objectData.getString("relationship-key")); + relationshipData.setRelationshipValue(objectData.getString("relationship-value")); + RelationshipDataList.add(relationshipData); + } + relationshipList.add(relationship); + relationship.setRelationshipData(RelationshipDataList); + + } + aaiServiceAndInstance.setRelationshipList(relationshipList); + return aaiServiceAndInstance; + } else { + return null; + } + + } + + List<String> getAreaTaList(String sourceCoverageAreaTAList) { + if (sourceCoverageAreaTAList == null || sourceCoverageAreaTAList.length() == 0) { + logger.error("getAreaTaList: sourceCoverageAreaTAList is null or length is 0"); + return null; + } + String[] strArr = sourceCoverageAreaTAList.split("\\|"); + return Arrays.asList(strArr); + } + + public AAIServiceAndInstance listServiceByIdUtil(JSONObject object) { + AAIServiceAndInstance aaiServiceAndInstance = new AAIServiceAndInstance(); + aaiServiceAndInstance.setServiceInstanceId(object.getString("service-instance-id")); + aaiServiceAndInstance.setServiceInstanceName(object.getString("service-instance-name")); + aaiServiceAndInstance.setEnvironmentContext(object.getString("environment-context")); + aaiServiceAndInstance.setOrchestrationStatus(object.getString("orchestration-status")); + aaiServiceAndInstance.setServiceType(object.getString("service-type")); + return aaiServiceAndInstance; + + } + + String getUseInterval(String serviceId) { + AAIServiceAndInstance aaiServiceAndInstance = new AAIServiceAndInstance(); + try { + // TODO + Response<JSONObject> response = this.aaiSliceService + .queryOrderByService(NsmfParamConstant.CUSTOM_5G, NsmfParamConstant.SERVICE_TYPE_5G, serviceId) + .execute(); + if (response.isSuccessful()) { + JSONObject object = response.body(); + logger.info("getUseInterval: queryOrderByService response is:{}", response.body()); + aaiServiceAndInstance = queryServiceUtil(object); + String orderId = getOrderIdFromRelation(aaiServiceAndInstance); + Response<JSONObject> orderResponse = this.aaiSliceService + .queryOrderByOrderId(NsmfParamConstant.CUSTOM_5G, NsmfParamConstant.SERVICE_TYPE_5G, orderId) + .execute(); + if (orderResponse.isSuccessful()) { + logger.info("getUseInterval: queryOrderByOrderId response is:{}", orderResponse.body()); + JSONObject orderObject = orderResponse.body(); + AAIServiceAndInstance aaiOrderServiceAndInstance = queryServiceUtil(orderObject); + String useInterval = aaiOrderServiceAndInstance.getWorkloadContext(); + return useInterval; + } else { + logger.error(String + .format("getUseInterval: Can not get queryOrderByOrderId[code={}, message={}]", response.code(), + response.message())); + return ""; + } + + } else { + logger.error(String + .format("getUseInterval: Can not get queryOrderByService[code={}, message={}]", response.code(), + response.message())); + return ""; + } + } catch (Exception e) { + logger.error(e.getMessage()); + return ""; + } + } + + String getOrderIdFromRelation(AAIServiceAndInstance aaiServiceAndInstance) { + //获取第一个元素,总共一个切片业务对应一个订单 + String orderId = ""; + if (aaiServiceAndInstance.getRelationshipList() != null + && aaiServiceAndInstance.getRelationshipList().size() > 0) { + Relationship relationship = aaiServiceAndInstance.getRelationshipList().get(0); + + if (null != relationship) { + List<org.onap.usecaseui.server.service.slicingdomain.aai.bean.RelationshipData> relationshipDataList = relationship + .getRelationshipData(); + + for (org.onap.usecaseui.server.service.slicingdomain.aai.bean.RelationshipData relationshipData : relationshipDataList) { + String relationKey = relationshipData.getRelationshipKey(); + if (relationKey.equals("service-instance.service-instance-id")) { + orderId = relationshipData.getRelationshipValue(); + } + } + } + } + + return orderId; + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceConvert.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceConvert.java new file mode 100644 index 00000000..6b007d19 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceConvert.java @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2019 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.service.nsmf.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.beanutils.BeanUtils; +import org.onap.usecaseui.server.bean.nsmf.common.PagedResult; +import org.onap.usecaseui.server.bean.nsmf.task.BusinessDemandInfo; +import org.onap.usecaseui.server.bean.nsmf.task.NsiAndSubNssiInfo; +import org.onap.usecaseui.server.bean.nsmf.task.NstInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskAuditInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskCreationInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskCreationProgress; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskList; +import org.onap.usecaseui.server.service.slicingdomain.aai.AAISliceService; +import org.onap.usecaseui.server.service.slicingdomain.so.bean.SOTask; +import org.onap.usecaseui.server.service.slicingdomain.so.bean.SOTaskRsp; +import org.onap.usecaseui.server.util.RestfulServices; +import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TaskMgtServiceConvert { + + private static final Logger logger = LoggerFactory.getLogger(TaskMgtServiceConvert.class); + + private GeneralConvertImpl generalConvert = new GeneralConvertImpl(); + private AAISliceService aaiSliceService; + + public TaskMgtServiceConvert() { + this(RestfulServices.create(AAISliceService.class)); + } + + public TaskMgtServiceConvert(AAISliceService aaiSliceService) { + this.aaiSliceService = aaiSliceService; + } + + void convertSlicingTaskList(SlicingTaskList targetSlicingTaskList, SOTaskRsp sourceSoTaskRsp, int pageNo, + int pageSize) + throws InvocationTargetException, IllegalAccessException { + if (sourceSoTaskRsp.getTask() == null) { + logger.error("convertSlicingTaskList: sourceSoTaskRsp.getTask() is null"); + return; + } + + List<SlicingTaskInfo> slicingTaskInfoList = new ArrayList<>(); + for (SOTask soTask : sourceSoTaskRsp.getTask()) { + SlicingTaskInfo slicingTaskInfo = new SlicingTaskInfo(); + BeanUtils.copyProperties(slicingTaskInfo, soTask); + JSONObject paramsObject = JSON.parseObject(soTask.getParams()); + slicingTaskInfo.setServiceSnssai(paramsObject.getString("ServiceProfile.sNSSAI")); + slicingTaskInfo.setServiceType(paramsObject.getString("ServiceProfile.sST")); + slicingTaskInfo.setCreateTime(soTask.getCreatedTime()); + slicingTaskInfo.setName(paramsObject.getString("ServiceName")); + slicingTaskInfoList.add(slicingTaskInfo); + } + PagedResult pagedOrderList = NsmfCommonUtil.getPagedList(slicingTaskInfoList, pageNo, pageSize); + targetSlicingTaskList.setSlicingTaskInfoList(pagedOrderList.getPagedList()); + targetSlicingTaskList.setRecordNumber(slicingTaskInfoList.size()); + } + + void convertTaskAuditInfo(SlicingTaskAuditInfo targetSlicingTaskAuditInfo, SOTask sourceSoTaskInfo) { + targetSlicingTaskAuditInfo.setTaskId(sourceSoTaskInfo.getTaskId()); + targetSlicingTaskAuditInfo.setTaskName(sourceSoTaskInfo.getName()); + targetSlicingTaskAuditInfo.setCreateTime(sourceSoTaskInfo.getCreatedTime()); + targetSlicingTaskAuditInfo.setProcessingStatus(sourceSoTaskInfo.getStatus()); + + JSONObject paramsObject = JSON.parseObject(sourceSoTaskInfo.getParams()); + if (paramsObject == null) { + logger.error("convertTaskAuditInfo: paramsObject is null"); + return; + } + + BusinessDemandInfo businessDemandInfo = new BusinessDemandInfo(); + convertBusinessDemandInfo(businessDemandInfo, paramsObject); + targetSlicingTaskAuditInfo.setBusinessDemandInfo(businessDemandInfo); + + NstInfo nstInfo = new NstInfo(); + convertNstInfo(nstInfo, paramsObject); + targetSlicingTaskAuditInfo.setNstInfo(nstInfo); + + NsiAndSubNssiInfo nsiAndSubNssiInfo = new NsiAndSubNssiInfo(); + convertNsiAndSubNssiInfo(nsiAndSubNssiInfo, paramsObject); + targetSlicingTaskAuditInfo.setNsiAndSubNssiInfo(nsiAndSubNssiInfo); + } + + void convertBusinessDemandInfo(BusinessDemandInfo targetBusinessDemandInfo, JSONObject paramsObject) { + + targetBusinessDemandInfo.setServiceName(paramsObject.getString("ServiceName")); + targetBusinessDemandInfo.setServiceSnssai(paramsObject.getString("ServiceProfile.sNSSAI")); + targetBusinessDemandInfo.setExpDataRateDL(paramsObject.getString("ServiceProfile.expDataRateDL")); + targetBusinessDemandInfo.setExpDataRateUL(paramsObject.getString("ServiceProfile.expDataRateUL")); + targetBusinessDemandInfo.setUeMobilityLevel(paramsObject.getString("ServiceProfile.uEMobilityLevel")); + targetBusinessDemandInfo.setLatency(paramsObject.getString("ServiceProfile.latency")); + + String useInterval = generalConvert.getUseInterval(paramsObject.getString("ServiceId")); + targetBusinessDemandInfo.setUseInterval(useInterval); + + String coverageAreaTA = paramsObject.getString("ServiceProfile.coverageAreaTAList"); + targetBusinessDemandInfo.setCoverageAreaTaList(generalConvert.getAreaTaList(coverageAreaTA)); + targetBusinessDemandInfo.setActivityFactor(paramsObject.getString("ServiceProfile.activityFactor")); + targetBusinessDemandInfo.setResourceSharingLevel(paramsObject.getString("ServiceProfile.resourceSharingLevel")); + targetBusinessDemandInfo.setAreaTrafficCapDL(paramsObject.getString("ServiceProfile.areaTrafficCapDL")); + targetBusinessDemandInfo.setAreaTrafficCapUL(paramsObject.getString("ServiceProfile.areaTrafficCapUL")); + targetBusinessDemandInfo.setMaxNumberOfUEs(paramsObject.getString("ServiceProfile.maxNumberofUEs")); + } + + void convertNstInfo(NstInfo nstInfo, JSONObject paramsObject) { + nstInfo.setNstId(paramsObject.getString("NSTId")); + nstInfo.setNstName(paramsObject.getString("NSTName")); + } + + void convertNsiAndSubNssiInfo(NsiAndSubNssiInfo nsiAndSubNssiInfo, JSONObject paramsObject) { + nsiAndSubNssiInfo.setSuggestNsiId(paramsObject.getString("suggestNSIId")); + nsiAndSubNssiInfo.setSuggestNsiName(paramsObject.getString("suggestNSIName")); + nsiAndSubNssiInfo.setAnSuggestNssiId(paramsObject.getString("AN.suggestNSSIId")); + nsiAndSubNssiInfo.setAnSuggestNssiName(paramsObject.getString("AN.suggestNSSIName")); + nsiAndSubNssiInfo.setAn5qi(paramsObject.getString("SliceProfile.AN.5QI")); + + String anCoverageAreaTA = paramsObject.getString("SliceProfile.AN.coverageAreaTAList"); + nsiAndSubNssiInfo.setAnCoverageAreaTaList(generalConvert.getAreaTaList(anCoverageAreaTA)); + nsiAndSubNssiInfo.setAnLatency(paramsObject.getString("SliceProfile.AN.latency")); + nsiAndSubNssiInfo.setAnScriptName(paramsObject.getString("AN.ScriptName")); + + nsiAndSubNssiInfo.setTnSuggestNssiId(paramsObject.getString("TN.suggestNSSIId")); + nsiAndSubNssiInfo.setTnSuggestNssiName(paramsObject.getString("TN.suggestNSSIName")); + nsiAndSubNssiInfo.setTnLatency(paramsObject.getString("SliceProfile.TN.latency")); + nsiAndSubNssiInfo.setTnBandwidth(paramsObject.getString("SliceProfile.TN.bandwidth")); + nsiAndSubNssiInfo.setTnScriptName(paramsObject.getString("TN.ScriptName")); + + nsiAndSubNssiInfo.setCnSuggestNssiId(paramsObject.getString("CN.suggestNSSIId")); + nsiAndSubNssiInfo.setCnSuggestNssiName(paramsObject.getString("CN.suggestNSSIName")); + nsiAndSubNssiInfo.setCnServiceSnssai(paramsObject.getString("SliceProfile.CN.sNSSAI")); + nsiAndSubNssiInfo.setCnResourceSharingLevel(paramsObject.getString("SliceProfile.CN.resourceSharingLevel")); + nsiAndSubNssiInfo.setCnUeMobilityLevel(paramsObject.getString("SliceProfile.CN.uEMobilityLevel")); + nsiAndSubNssiInfo.setCnLatency(paramsObject.getString("SliceProfile.CN.latency")); + nsiAndSubNssiInfo.setCnMaxNumberOfUes(paramsObject.getString("SliceProfile.CN.maxNumberofUEs")); + nsiAndSubNssiInfo.setCnActivityFactor(paramsObject.getString("SliceProfile.CN.activityFactor")); + nsiAndSubNssiInfo.setCnExpDataRateDl(paramsObject.getString("SliceProfile.CN.expDataRateDL")); + nsiAndSubNssiInfo.setCnExpDataRateUl(paramsObject.getString("SliceProfile.CN.expDataRateUL")); + nsiAndSubNssiInfo.setCnAreaTrafficCapDl(paramsObject.getString("SliceProfile.CN.areaTrafficCapDL")); + nsiAndSubNssiInfo.setCnAreaTrafficCapUl(paramsObject.getString("SliceProfile.CN.areaTrafficCapUL")); + nsiAndSubNssiInfo.setCnScriptName(paramsObject.getString("CN.ScriptName")); + } + + void convertTaskAuditToSoTask(SOTask targetSoTaskInfo, SlicingTaskAuditInfo sourceSlicingTaskAuditInfo) { + if (sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo() == null) { + logger.error("convertTaskAuditToSoTask: sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo() is null"); + return; + } + + JSONObject jsonObject = JSONObject.parseObject(targetSoTaskInfo.getParams()); + jsonObject.put("suggestNSIId", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getSuggestNsiId()); + jsonObject.put("suggestNSIName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getSuggestNsiName()); + jsonObject.put("AN.suggestNSSIId", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAnSuggestNssiId()); + jsonObject.put("AN.suggestNSSIName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAnSuggestNssiName()); + jsonObject.put("SliceProfile.AN.latency", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAnLatency()); + jsonObject.put("SliceProfile.AN.5QI", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAn5qi()); + + String aNCoverageAreaTAList = getAreaTaListString + (sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAnCoverageAreaTaList(), '|'); + jsonObject.put("SliceProfile.AN.coverageAreaTAList", aNCoverageAreaTAList); + jsonObject.put("AN.ScriptName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getAnScriptName()); + + jsonObject.put("TN.suggestNSSIId", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getTnSuggestNssiId()); + jsonObject.put("TN.suggestNSSIName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getTnSuggestNssiName()); + jsonObject.put("SliceProfile.TN.bandwidth", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getTnBandwidth()); + jsonObject.put("SliceProfile.TN.latency", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getTnLatency()); + jsonObject.put("TN.ScriptName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getTnScriptName()); + + jsonObject.put("CN.suggestNSSIId", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnSuggestNssiId()); + jsonObject.put("CN.suggestNSSIName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnSuggestNssiName()); + jsonObject + .put("SliceProfile.CN.sNSSAI", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnServiceSnssai()); + jsonObject.put("SliceProfile.CN.resourceSharingLevel", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnResourceSharingLevel()); + jsonObject.put("SliceProfile.CN.uEMobilityLevel", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnUeMobilityLevel()); + jsonObject.put("SliceProfile.CN.latency", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnLatency()); + jsonObject.put("SliceProfile.CN.maxNumberofUEs", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnMaxNumberOfUes()); + jsonObject.put("SliceProfile.CN.activityFactor", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnActivityFactor()); + jsonObject.put("SliceProfile.CN.expDataRateDL", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnExpDataRateDl()); + jsonObject.put("SliceProfile.CN.expDataRateUL", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnExpDataRateUl()); + jsonObject.put("SliceProfile.CN.areaTrafficCapDL", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnAreaTrafficCapDl()); + jsonObject.put("SliceProfile.CN.areaTrafficCapUL", + sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnAreaTrafficCapUl()); + jsonObject.put("CN.ScriptName", sourceSlicingTaskAuditInfo.getNsiAndSubNssiInfo().getCnScriptName()); + String param = jsonObject.toJSONString(); + targetSoTaskInfo.setParams(param); + } + + String getAreaTaListString(List<String> anCoverageAreaTaList, char separator) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < anCoverageAreaTaList.size(); i++) { + sb.append(anCoverageAreaTaList.get(i)).append(separator); + } + return sb.toString().substring(0, sb.toString().length() - 1); + } + + void convertTaskCreationInfo(SlicingTaskCreationInfo slicingTaskCreationInfo, SOTask soTask) { + slicingTaskCreationInfo.setTaskId(soTask.getTaskId()); + slicingTaskCreationInfo.setCreateTime(soTask.getCreatedTime()); + slicingTaskCreationInfo.setProcessingStatus(soTask.getStatus()); + slicingTaskCreationInfo.setTaskName(soTask.getName()); + + JSONObject paramsObject = JSON.parseObject(soTask.getParams()); + if (paramsObject == null) { + logger.error("convertTaskCreationInfo: paramsObject is null"); + return; + } + + BusinessDemandInfo businessDemandInfo = new BusinessDemandInfo(); + convertCreationBusinessDemandInfo(businessDemandInfo, paramsObject); + slicingTaskCreationInfo.setBusinessDemandInfo(businessDemandInfo); + + NstInfo nstInfo = new NstInfo(); + convertNstInfo(nstInfo, paramsObject); + slicingTaskCreationInfo.setNstInfo(nstInfo); + } + + void convertCreationBusinessDemandInfo(BusinessDemandInfo targetBusinessDemandInfo, JSONObject paramsObject) { + targetBusinessDemandInfo.setServiceName(paramsObject.getString("ServiceName")); + targetBusinessDemandInfo.setServiceSnssai(paramsObject.getString("ServiceProfile.sNSSAI")); + targetBusinessDemandInfo.setExpDataRateDL(paramsObject.getString("ServiceProfile.expDataRateDL")); + targetBusinessDemandInfo.setExpDataRateUL(paramsObject.getString("ServiceProfile.expDataRateUL")); + targetBusinessDemandInfo.setUeMobilityLevel(paramsObject.getString("ServiceProfile.uEMobilityLevel")); + targetBusinessDemandInfo.setLatency(paramsObject.getString("ServiceProfile.latency")); + String useInterval = generalConvert.getUseInterval(paramsObject.getString("ServiceId")); + targetBusinessDemandInfo.setUseInterval(useInterval); + + String coverageAreaTA = paramsObject.getString("ServiceProfile.coverageAreaTAList"); + targetBusinessDemandInfo.setCoverageAreaTaList(generalConvert.getAreaTaList(coverageAreaTA)); + targetBusinessDemandInfo.setActivityFactor(paramsObject.getString("ServiceProfile.activityFactor")); + targetBusinessDemandInfo.setResourceSharingLevel(paramsObject.getString("ServiceProfile.resourceSharingLevel")); + targetBusinessDemandInfo.setAreaTrafficCapDL(paramsObject.getString("ServiceProfile.areaTrafficCapDL")); + targetBusinessDemandInfo.setAreaTrafficCapUL(paramsObject.getString("ServiceProfile.areaTrafficCapUL")); + targetBusinessDemandInfo.setMaxNumberOfUEs(paramsObject.getString("ServiceProfile.maxNumberofUEs")); + } + + void convertTaskCreationProgress(SlicingTaskCreationProgress slicingTaskCreationProgress, SOTask soTask) { + + JSONObject paramsObject = JSON.parseObject(soTask.getParams()); + if (paramsObject == null) { + logger.error("convertTaskCreationProgress: paramsObject is null"); + return; + } + + String anProgress = paramsObject.getString("AN.progress"); + slicingTaskCreationProgress.setAnProgress(anProgress); + + String tnProgress = paramsObject.getString("TN.progress"); + slicingTaskCreationProgress.setTnProgress(tnProgress); + + String cnProgress = paramsObject.getString("CN.progress"); + slicingTaskCreationProgress.setCnProgress(cnProgress); + + String anStatus = paramsObject.getString("AN.status"); + slicingTaskCreationProgress.setAnStatus(anStatus); + + String tnStatus = paramsObject.getString("TN.status"); + slicingTaskCreationProgress.setTnStatus(tnStatus); + + String cnStatus = paramsObject.getString("CN.status"); + slicingTaskCreationProgress.setCnStatus(cnStatus); + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java new file mode 100644 index 00000000..6c2a10fb --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/TaskMgtServiceImpl.java @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2019 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.service.nsmf.impl; + +import java.lang.reflect.Type; +import java.util.List; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import okhttp3.MediaType; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import org.onap.usecaseui.server.bean.nsmf.common.ResultHeader; +import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskAuditInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskCreationInfo; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskCreationProgress; +import org.onap.usecaseui.server.bean.nsmf.task.SlicingTaskList; +import org.onap.usecaseui.server.constant.nsmf.NsmfCodeConstant; + +import org.onap.usecaseui.server.service.nsmf.TaskMgtService; +import org.onap.usecaseui.server.service.slicingdomain.so.SOSliceService; +import org.onap.usecaseui.server.service.slicingdomain.so.bean.SOTask; +import org.onap.usecaseui.server.service.slicingdomain.so.bean.SOTaskRsp; +import org.onap.usecaseui.server.util.RestfulServices; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Service; +import retrofit2.Response; + +@Service("TaskMgtService") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +public class TaskMgtServiceImpl implements TaskMgtService { + + private static final Logger logger = LoggerFactory.getLogger(TaskMgtServiceImpl.class); + private TaskMgtServiceConvert taskMgtServiceConvert = new TaskMgtServiceConvert(); + + private SOSliceService soSliceService; + + public TaskMgtServiceImpl() { + this(RestfulServices.create(SOSliceService.class)); + } + + public TaskMgtServiceImpl(SOSliceService soSliceService) { + this.soSliceService = soSliceService; + } + + @Override + public ServiceResult querySlicingTask(int pageNo, int pageSize) { + + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + + SlicingTaskList slicingTaskList = new SlicingTaskList(); + SOTaskRsp soTaskRsp = new SOTaskRsp(); + String resultMsg; + + try { + Response<JSONArray> response = this.soSliceService.listTask().execute(); + if (response.isSuccessful()) { + Gson gson = new Gson(); + Type type = new TypeToken<List<SOTask>>() { + }.getType(); + soTaskRsp.setTask(gson.fromJson(response.body().toString(), type)); + logger.info("querySlicingTask: listTask response is:{}", response.body().toString()); + taskMgtServiceConvert.convertSlicingTaskList(slicingTaskList, soTaskRsp, pageNo, pageSize); + resultMsg = "5G slicing task query result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error( + String.format("querySlicingTask: Can not get slicingTaskList[code={}, message={}]", response.code(), + response.message())); + resultMsg = "5G slicing task result query failed!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task result query failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("querySlicingTask: 5G slicing task result query has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + serviceResult.setResult_body(slicingTaskList); + return serviceResult; + } + + @Override + public ServiceResult querySlicingTaskByStatus(String status, int pageNo, int pageSize) { + + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + + SlicingTaskList slicingTaskList = new SlicingTaskList(); + SOTaskRsp soTaskRsp = new SOTaskRsp(); + String resultMsg; + try { + Response<JSONArray> response = this.soSliceService.listTaskByStage(status).execute(); + if (response.isSuccessful()) { + Gson gson = new Gson(); + Type type = new TypeToken<List<SOTask>>() { + }.getType(); + soTaskRsp.setTask(gson.fromJson(response.body().toString(), type)); + logger.info("querySlicingTaskByStatus: listTaskByStage response is:{}", response.body().toString()); + taskMgtServiceConvert.convertSlicingTaskList(slicingTaskList, soTaskRsp, pageNo, pageSize); + resultMsg = "5G slicing task query based on status result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error(String.format("querySlicingTaskByStatus: Can not get slicingTaskList[code={}, message={}]", + response.code(), + response.message())); + resultMsg = "5G slicing task result query based on status failed. "; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task result query based on status failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("querySlicingTaskByStatus: 5G slicing task result query based on status has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + serviceResult.setResult_body(slicingTaskList); + return serviceResult; + } + + @Override + public ServiceResult queryTaskAuditInfo(String taskId) { + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + + SlicingTaskAuditInfo slicingTaskAuditInfo = new SlicingTaskAuditInfo(); + String resultMsg = ""; + + try { + // TODO + Response<SOTask> response = this.soSliceService.getTaskById(taskId).execute(); + if (response.isSuccessful()) { + SOTask soTaskInfo = response.body(); + Gson gson = new Gson(); + logger.info("queryTaskAuditInfo: getTaskById response is:{}", gson.toJson(soTaskInfo).toString()); + taskMgtServiceConvert.convertTaskAuditInfo(slicingTaskAuditInfo, soTaskInfo); + // return normal result code + resultMsg = "5G slicing task configure audit information query result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error(String.format("queryTaskAuditInfo: Can not get slicingTaskAuditInfo[code={}, message={}]", + response.code(), + response.message())); + resultMsg = "5G slicing task configure audit information query failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task configure audit information query failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("queryTaskAuditInfo: 5G slicing task configure audit information query has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + serviceResult.setResult_body(slicingTaskAuditInfo); + return serviceResult; + } + + public ServiceResult updateTaskAuditInfo(SlicingTaskAuditInfo slicingTaskAuditInfo) { + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + String resultMsg; + try { + // TODO + Response<SOTask> response = this.soSliceService.getTaskById(slicingTaskAuditInfo.getTaskId()).execute(); + if (response.isSuccessful()) { + SOTask soTaskInfo = response.body(); + Gson gson = new Gson(); + logger.info("updateTaskAuditInfo: getTaskById response is:{}", gson.toJson(soTaskInfo).toString()); + taskMgtServiceConvert.convertTaskAuditToSoTask(soTaskInfo, slicingTaskAuditInfo); + + String jsonstr = JSON.toJSONString(soTaskInfo); + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonstr.toString()); + Response<ResponseBody> updateResponse = soSliceService + .updateService(slicingTaskAuditInfo.getTaskId(), requestBody).execute(); + + if (updateResponse.isSuccessful()) { + Response<ResponseBody> commitResponse = this.soSliceService + .commitTask(slicingTaskAuditInfo.getTaskId()).execute(); + if (commitResponse.isSuccessful()) { + resultMsg = "5G slicing task submit result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error(String.format("updateTaskAuditInfo: Can not commitTask [code={}, message={}]", + commitResponse.code(), + commitResponse.message())); + resultMsg = "5G slicing task submit failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } else { + logger.error(String + .format("updateTaskAuditInfo: Can not updateService [code={}, message={}]", response.code(), + response.message())); + resultMsg = "5G slicing task submit failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } else { + logger.error(String.format("updateTaskAuditInfo: Can not get slicingTaskAuditInfo[code={}, message={}]", + response.code(), + response.message())); + resultMsg = "5G slicing task submit failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task submit failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("updateTaskAuditInfo: 5G slicing task submit has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + return serviceResult; + } + + @Override + public ServiceResult queryTaskCreationInfo(String taskId) { + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + + SlicingTaskCreationInfo slicingTaskCreationInfo = new SlicingTaskCreationInfo(); + String resultMsg; + + try { + // TODO + Response<SOTask> response = this.soSliceService.getTaskByIdD(taskId).execute(); + if (response.isSuccessful()) { + Gson gson = new Gson(); + SOTask soTask = response.body(); + logger.info("updateTaskAuditInfo: getTaskById response is:{}", gson.toJson(soTask).toString()); + taskMgtServiceConvert.convertTaskCreationInfo(slicingTaskCreationInfo, soTask); + // return normal result code + resultMsg = "5G slicing task creation infomation query result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error(String + .format("updateTaskAuditInfo: Can not get slicingTaskCreationInfo[code={}, message={}]", + response.code(), + response.message())); + resultMsg = "5G slicing task creation infomation query failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task creation infomation query failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("updateTaskAuditInfo: 5G slicing task creation infomation query has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + serviceResult.setResult_body(slicingTaskCreationInfo); + return serviceResult; + } + + @Override + public ServiceResult queryTaskCreationProgress(String taskId) { + ServiceResult serviceResult = new ServiceResult(); + ResultHeader resultHeader = new ResultHeader(); + + SlicingTaskCreationProgress slicingTaskCreationProgress = new SlicingTaskCreationProgress(); + String resultMsg; + + try { + // TODO + Response<SOTask> response = this.soSliceService.getTaskByIdD(taskId).execute(); + if (response.isSuccessful()) { + SOTask soTask = response.body(); + Gson gson = new Gson(); + logger.info("queryTaskCreationProgress: getTaskById response is:{}", gson.toJson(soTask).toString()); + taskMgtServiceConvert.convertTaskCreationProgress(slicingTaskCreationProgress, soTask); + resultMsg = "5G slicing task operation progress query result."; + resultHeader.setResult_code(NsmfCodeConstant.SUCCESS_CODE); + } else { + logger.error(String + .format("queryTaskCreationProgress: Can not get slicingTaskCreationProgress[code={}, message={}]", + response.code(), response.message())); + resultMsg = "5G slicing task operation progress query failed."; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + } + } catch (Exception e) { + resultMsg = "5G slicing task operation progress query failed. Unknown exception occurred!"; + resultHeader.setResult_code(NsmfCodeConstant.ERROR_CODE_UNKNOWN); + logger.error(e.getMessage()); + } + + logger.info(resultMsg); + logger.info("queryTaskCreationProgress: 5G slicing task operation progress has been finished."); + resultHeader.setResult_message(resultMsg); + serviceResult.setResult_header(resultHeader); + serviceResult.setResult_body(slicingTaskCreationProgress); + return serviceResult; + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/util/nsmf/NsmfCommonUtil.java b/server/src/main/java/org/onap/usecaseui/server/util/nsmf/NsmfCommonUtil.java new file mode 100644 index 00000000..3012a723 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/util/nsmf/NsmfCommonUtil.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 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.util.nsmf; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; +import org.onap.usecaseui.server.bean.nsmf.common.PagedResult; +import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant; + + +public class NsmfCommonUtil { + + public static String timestamp2Time(String timeStamp) throws ParseException { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(NsmfParamConstant.DATE_FORMAT); + Date date = simpleDateFormat.parse(timeStamp); + long time = date.getTime(); + return String.valueOf(time); + } + + public static String time2Timestamp(String time) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(NsmfParamConstant.DATE_FORMAT); + long longTime = new Long(time); + Date date = new Date(longTime); + return simpleDateFormat.format(date); + } + + public static <T> PagedResult getPagedList(List<T> list, int pageNo, int pageSize) { + if (list == null || pageNo < 1 || (pageNo - 1) * pageSize > list.size()) { + return new PagedResult(0, Collections.EMPTY_LIST); + } + list = list.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); + return new PagedResult(list.size(), list ); + } +} |