1af6d15c06cd79915575b29fe612180a820d8845
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2020, CMCC Technologies Co., Ltd.
6  #
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
10  #
11  #       http://www.apache.org/licenses/LICENSE-2.0
12  #
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=========================================================
19  */
20
21 package org.onap.so.adapters.nssmf.manager.impl.external;
22
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;
38 import java.util.Map;
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;
42
43
44 public class ExternalAnNssmfManager extends ExternalNssmfManager {
45
46     /**
47      * request body params
48      */
49     private Map<String, String> bodyParams = new HashMap<>();
50
51     @Override
52     protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
53         Map<String, Object> request = new HashMap<>();
54
55         AnSliceProfile anSliceProfile = nbiRequest.getAllocateAnNssi().getSliceProfile();
56
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());
67
68         request.put("attributeListIn", ranSliceProfile);
69         return marshal(request);
70     }
71
72     @Override
73     protected void doAfterRequest() throws ApplicationException {
74         if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
75             String nssiId;
76             if (ActionType.ALLOCATE.equals(actionType)) {
77                 @SuppressWarnings("unchecked")
78                 Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
79                 nssiId = response.get("href");
80             } else {
81                 nssiId = this.bodyParams.get("nssiId");
82             }
83
84             NssiResponse resp = new NssiResponse();
85             resp.setJobId(UUID.randomUUID().toString());
86             resp.setNssiId(nssiId);
87
88             RestResponse returnRsp = new RestResponse();
89
90             returnRsp.setStatus(202);
91             returnRsp.setResponseContent(marshal(resp));
92             restResponse = returnRsp;
93
94             ResourceOperationStatus status =
95                     new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
96             status.setResourceInstanceID(nssiId);
97             status.setOperType(actionType.toString());
98
99             updateDbStatus(status, restResponse.getStatus(), JobStatus.STARTED,
100                     NssmfAdapterUtil.getStatusDesc(actionType));
101         }
102         // todo
103     }
104
105     @Override
106     protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
107         // TODO
108         return null;
109     }
110
111     @Override
112     protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
113         this.bodyParams.clear();
114         this.bodyParams.put("nssiId", deAllocateNssi.getNssiId());
115
116         Map<String, String> request = new HashMap<>();
117         request.put("nSSId", deAllocateNssi.getNssiId());
118         return marshal(request);
119     }
120
121
122     @Override
123     public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
124         // TODO
125         return null;
126     }
127
128     @Override
129     public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
130         // TODO
131         NssiResponse resp = new NssiResponse();
132         String nssiId = nbiRequest.getActDeActNssi().getNssiId();
133         resp.setJobId(UUID.randomUUID().toString());
134         resp.setNssiId(nssiId);
135
136         RestResponse returnRsp = new RestResponse();
137
138         returnRsp.setStatus(202);
139         returnRsp.setResponseContent(marshal(resp));
140
141         ResourceOperationStatus status =
142                 new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
143         status.setResourceInstanceID(nssiId);
144         status.setOperType(actionType.toString());
145
146         updateDbStatus(status, returnRsp.getStatus(), JobStatus.FINISHED, NssmfAdapterUtil.getStatusDesc(actionType));
147         return returnRsp;
148     }
149
150     @Override
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");
156
157         JobStatusResponse jobStatusResponse = new JobStatusResponse();
158         jobStatusResponse.setResponseDescriptor(responseDescriptor);
159
160         RestResponse restResponse = new RestResponse();
161         restResponse.setStatus(200);
162         restResponse.setResponseContent(marshal(jobStatusResponse));
163
164         updateRequestDbJobStatus(responseDescriptor, status, restResponse);
165
166         status.setProgress(Integer.toString(responseDescriptor.getProgress()));
167
168         return restResponse;
169     }
170
171     @Override
172     protected SelectionType doQueryNSSISelectionCapability() {
173         return SelectionType.NSSMF;
174     }
175 }