8e5793d559640687f846f5018d47c4278132d8c9
[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.DeAllocateNssi;
31 import org.onap.so.beans.nsmf.NssiResponse;
32 import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
33 import org.onap.so.beans.nsmf.ResponseDescriptor;
34 import org.onap.so.beans.nsmf.JobStatusResponse;
35 import org.onap.so.db.request.beans.ResourceOperationStatus;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.UUID;
39 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
40 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
41
42
43 public class ExternalAnNssmfManager extends ExternalNssmfManager {
44
45     private Map<String, String> bodyParams = new HashMap<>(); // request body params
46
47     @Override
48     protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
49         Map<String, Object> request = new HashMap<>();
50         request.put("attributeListIn", nbiRequest.getAllocateAnNssi().getSliceProfile());
51         return marshal(request);
52     }
53
54     @Override
55     protected void doAfterRequest() throws ApplicationException {
56         if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
57             String nssiId;
58             if (ActionType.ALLOCATE.equals(actionType)) {
59                 @SuppressWarnings("unchecked")
60                 Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
61                 nssiId = response.get("href");
62             } else {
63                 nssiId = this.bodyParams.get("nssiId");
64             }
65
66             NssiResponse resp = new NssiResponse();
67             resp.setJobId(UUID.randomUUID().toString());
68             resp.setNssiId(nssiId);
69
70             RestResponse returnRsp = new RestResponse();
71
72             returnRsp.setStatus(202);
73             returnRsp.setResponseContent(marshal(resp));
74             restResponse = returnRsp;
75
76             ResourceOperationStatus status =
77                     new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
78             status.setResourceInstanceID(nssiId);
79
80             updateDbStatus(status, restResponse.getStatus(), JobStatus.FINISHED,
81                     NssmfAdapterUtil.getStatusDesc(actionType));
82         }
83         // todo
84     }
85
86     @Override
87     protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
88         // TODO
89         return null;
90     }
91
92     @Override
93     protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
94         this.bodyParams.clear();
95         this.bodyParams.put("nssiId", deAllocateNssi.getNssiId());
96
97         Map<String, String> request = new HashMap<>();
98         request.put("nSSId", deAllocateNssi.getNssiId());
99         return marshal(request);
100     }
101
102
103     @Override
104     public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
105         // TODO
106         return null;
107     }
108
109     @Override
110     public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
111         // TODO
112         return null;
113     }
114
115     @Override
116     protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
117         ResponseDescriptor responseDescriptor = new ResponseDescriptor();
118         responseDescriptor.setStatus(JobStatus.FINISHED.toString());
119         responseDescriptor.setProgress(100);
120
121         JobStatusResponse jobStatusResponse = new JobStatusResponse();
122         jobStatusResponse.setResponseDescriptor(responseDescriptor);
123
124         RestResponse restResponse = new RestResponse();
125         restResponse.setStatus(200);
126         restResponse.setResponseContent(marshal(jobStatusResponse));
127
128         updateRequestDbJobStatus(responseDescriptor, status, restResponse);
129
130         return restResponse;
131     }
132
133     @Override
134     protected SelectionType doQueryNSSISelectionCapability() {
135         return SelectionType.NSSMF;
136     }
137 }