2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
7 # Licensed under the Apache License, Version 2.0 (the "License")
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.nssmf.manager.impl.external;
23 import org.onap.so.adapters.nssmf.entity.RestResponse;
24 import org.onap.so.adapters.nssmf.enums.ActionType;
25 import org.onap.so.adapters.nssmf.enums.JobStatus;
26 import org.onap.so.adapters.nssmf.enums.SelectionType;
27 import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
28 import org.onap.so.adapters.nssmf.manager.impl.ExternalNssmfManager;
29 import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
30 import org.onap.so.beans.nsmf.AnSliceProfile;
31 import org.onap.so.beans.nsmf.DeAllocateNssi;
32 import org.onap.so.beans.nsmf.NssiResponse;
33 import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
34 import org.onap.so.beans.nsmf.ResponseDescriptor;
35 import org.onap.so.beans.nsmf.JobStatusResponse;
36 import org.onap.so.db.request.beans.ResourceOperationStatus;
37 import java.util.HashMap;
39 import java.util.UUID;
40 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
41 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
44 public class ExternalAnNssmfManager extends ExternalNssmfManager {
46 private Map<String, String> bodyParams = new HashMap<>(); // request body params
49 protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
50 Map<String, Object> request = new HashMap<>();
52 AnSliceProfile anSliceProfile = nbiRequest.getAllocateAnNssi().getSliceProfile();
54 RanSliceProfile ranSliceProfile = new RanSliceProfile();
55 ranSliceProfile.setSliceProfileId(anSliceProfile.getSliceProfileId());
56 ranSliceProfile.setSNSSAIList(anSliceProfile.getSNSSAIList());
57 ranSliceProfile.setPLMNIdList(anSliceProfile.getPLMNIdList());
58 ranSliceProfile.setPerfReq(anSliceProfile.getPerfReq());
59 ranSliceProfile.setMaxNumberofUEs(anSliceProfile.getMaxNumberOfUEs());
60 ranSliceProfile.setCoverageAreaTAList(anSliceProfile.getCoverageAreaTAList());
61 ranSliceProfile.setLatency(anSliceProfile.getLatency());
62 ranSliceProfile.setUEMobilityLevel(anSliceProfile.getUeMobilityLevel());
63 ranSliceProfile.setResourceSharingLevel(anSliceProfile.getResourceSharingLevel());
65 request.put("attributeListIn", ranSliceProfile);
66 return marshal(request);
70 protected void doAfterRequest() throws ApplicationException {
71 if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
73 if (ActionType.ALLOCATE.equals(actionType)) {
74 @SuppressWarnings("unchecked")
75 Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
76 nssiId = response.get("href");
78 nssiId = this.bodyParams.get("nssiId");
81 NssiResponse resp = new NssiResponse();
82 resp.setJobId(UUID.randomUUID().toString());
83 resp.setNssiId(nssiId);
85 RestResponse returnRsp = new RestResponse();
87 returnRsp.setStatus(202);
88 returnRsp.setResponseContent(marshal(resp));
89 restResponse = returnRsp;
91 ResourceOperationStatus status =
92 new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
93 status.setResourceInstanceID(nssiId);
94 status.setOperType(actionType.toString());
96 updateDbStatus(status, restResponse.getStatus(), JobStatus.FINISHED,
97 NssmfAdapterUtil.getStatusDesc(actionType));
103 protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
109 protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
110 this.bodyParams.clear();
111 this.bodyParams.put("nssiId", deAllocateNssi.getNssiId());
113 Map<String, String> request = new HashMap<>();
114 request.put("nSSId", deAllocateNssi.getNssiId());
115 return marshal(request);
120 public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
126 public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
132 protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
133 ResponseDescriptor responseDescriptor = new ResponseDescriptor();
134 responseDescriptor.setStatus(JobStatus.FINISHED.toString());
135 responseDescriptor.setProgress(100);
136 responseDescriptor.setStatusDescription("Finished");
138 JobStatusResponse jobStatusResponse = new JobStatusResponse();
139 jobStatusResponse.setResponseDescriptor(responseDescriptor);
141 RestResponse restResponse = new RestResponse();
142 restResponse.setStatus(200);
143 restResponse.setResponseContent(marshal(jobStatusResponse));
145 updateRequestDbJobStatus(responseDescriptor, status, restResponse);
147 status.setProgress(Integer.toString(responseDescriptor.getProgress()));
153 protected SelectionType doQueryNSSISelectionCapability() {
154 return SelectionType.NSSMF;