20ad3d10b7b52b38cecd158d6d95ac349e15b315
[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     private Map<String, String> bodyParams = new HashMap<>(); // request body params
47
48     @Override
49     protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
50         Map<String, Object> request = new HashMap<>();
51
52         AnSliceProfile anSliceProfile = nbiRequest.getAllocateAnNssi().getSliceProfile();
53
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());
64
65         request.put("attributeListIn", ranSliceProfile);
66         return marshal(request);
67     }
68
69     @Override
70     protected void doAfterRequest() throws ApplicationException {
71         if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
72             String nssiId;
73             if (ActionType.ALLOCATE.equals(actionType)) {
74                 @SuppressWarnings("unchecked")
75                 Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
76                 nssiId = response.get("href");
77             } else {
78                 nssiId = this.bodyParams.get("nssiId");
79             }
80
81             NssiResponse resp = new NssiResponse();
82             resp.setJobId(UUID.randomUUID().toString());
83             resp.setNssiId(nssiId);
84
85             RestResponse returnRsp = new RestResponse();
86
87             returnRsp.setStatus(202);
88             returnRsp.setResponseContent(marshal(resp));
89             restResponse = returnRsp;
90
91             ResourceOperationStatus status =
92                     new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
93             status.setResourceInstanceID(nssiId);
94             status.setOperType(actionType.toString());
95
96             updateDbStatus(status, restResponse.getStatus(), JobStatus.STARTED,
97                     NssmfAdapterUtil.getStatusDesc(actionType));
98         }
99         // todo
100     }
101
102     @Override
103     protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
104         // TODO
105         return null;
106     }
107
108     @Override
109     protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
110         this.bodyParams.clear();
111         this.bodyParams.put("nssiId", deAllocateNssi.getNssiId());
112
113         Map<String, String> request = new HashMap<>();
114         request.put("nSSId", deAllocateNssi.getNssiId());
115         return marshal(request);
116     }
117
118
119     @Override
120     public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
121         // TODO
122         return null;
123     }
124
125     @Override
126     public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
127         // TODO
128         return null;
129     }
130
131     @Override
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");
137
138         JobStatusResponse jobStatusResponse = new JobStatusResponse();
139         jobStatusResponse.setResponseDescriptor(responseDescriptor);
140
141         RestResponse restResponse = new RestResponse();
142         restResponse.setStatus(200);
143         restResponse.setResponseContent(marshal(jobStatusResponse));
144
145         updateRequestDbJobStatus(responseDescriptor, status, restResponse);
146
147         status.setProgress(Integer.toString(responseDescriptor.getProgress()));
148
149         return restResponse;
150     }
151
152     @Override
153     protected SelectionType doQueryNSSISelectionCapability() {
154         return SelectionType.NSSMF;
155     }
156 }