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 {
49 private Map<String, String> bodyParams = new HashMap<>();
52 protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
53 Map<String, Object> request = new HashMap<>();
55 AnSliceProfile anSliceProfile = nbiRequest.getAllocateAnNssi().getSliceProfile();
57 RanSliceProfile ranSliceProfile = new RanSliceProfile();
58 ranSliceProfile.setSliceProfileId(anSliceProfile.getSliceProfileId());
59 ranSliceProfile.setSNSSAIList(anSliceProfile.getSNSSAIList());
60 ranSliceProfile.setPLMNIdList(anSliceProfile.getPLMNIdList());
61 ranSliceProfile.setPerfReq(anSliceProfile.getPerfReq());
62 ranSliceProfile.setMaxNumberofUEs(anSliceProfile.getMaxNumberOfUEs());
63 ranSliceProfile.setCoverageAreaTAList(anSliceProfile.getCoverageAreaTAList());
64 ranSliceProfile.setLatency(anSliceProfile.getLatency());
65 ranSliceProfile.setUEMobilityLevel(anSliceProfile.getUeMobilityLevel());
66 ranSliceProfile.setResourceSharingLevel(anSliceProfile.getResourceSharingLevel());
68 request.put("attributeListIn", ranSliceProfile);
69 return marshal(request);
73 protected void doAfterRequest() throws ApplicationException {
74 if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
76 if (ActionType.ALLOCATE.equals(actionType)) {
77 @SuppressWarnings("unchecked")
78 Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
79 nssiId = response.get("href");
81 nssiId = this.bodyParams.get("nssiId");
84 NssiResponse resp = new NssiResponse();
85 resp.setJobId(UUID.randomUUID().toString());
86 resp.setNssiId(nssiId);
88 RestResponse returnRsp = new RestResponse();
90 returnRsp.setStatus(202);
91 returnRsp.setResponseContent(marshal(resp));
92 restResponse = returnRsp;
94 ResourceOperationStatus status =
95 new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
96 status.setResourceInstanceID(nssiId);
97 status.setOperType(actionType.toString());
99 updateDbStatus(status, restResponse.getStatus(), JobStatus.STARTED,
100 NssmfAdapterUtil.getStatusDesc(actionType));
106 protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
112 protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
113 this.bodyParams.clear();
114 this.bodyParams.put("nssiId", deAllocateNssi.getNssiId());
116 Map<String, String> request = new HashMap<>();
117 request.put("nSSId", deAllocateNssi.getNssiId());
118 return marshal(request);
123 public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
129 public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
131 NssiResponse resp = new NssiResponse();
132 String nssiId = nbiRequest.getActDeActNssi().getNssiId();
133 resp.setJobId(UUID.randomUUID().toString());
134 resp.setNssiId(nssiId);
136 RestResponse returnRsp = new RestResponse();
138 returnRsp.setStatus(202);
139 returnRsp.setResponseContent(marshal(resp));
141 ResourceOperationStatus status =
142 new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
143 status.setResourceInstanceID(nssiId);
144 status.setOperType(actionType.toString());
146 updateDbStatus(status, returnRsp.getStatus(), JobStatus.FINISHED, NssmfAdapterUtil.getStatusDesc(actionType));
151 protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
152 ResponseDescriptor responseDescriptor = new ResponseDescriptor();
153 responseDescriptor.setStatus(JobStatus.FINISHED.toString());
154 responseDescriptor.setProgress(100);
155 responseDescriptor.setStatusDescription("Finished");
157 JobStatusResponse jobStatusResponse = new JobStatusResponse();
158 jobStatusResponse.setResponseDescriptor(responseDescriptor);
160 RestResponse restResponse = new RestResponse();
161 restResponse.setStatus(200);
162 restResponse.setResponseContent(marshal(jobStatusResponse));
164 updateRequestDbJobStatus(responseDescriptor, status, restResponse);
166 status.setProgress(Integer.toString(responseDescriptor.getProgress()));
172 protected SelectionType doQueryNSSISelectionCapability() {
173 return SelectionType.NSSMF;