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;
23 import org.apache.http.Header;
24 import org.apache.http.message.BasicHeader;
25 import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
26 import org.onap.so.adapters.nssmf.entity.RestResponse;
27 import org.onap.so.adapters.nssmf.enums.SelectionType;
28 import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
29 import org.onap.so.beans.nsmf.*;
30 import org.onap.so.db.request.beans.ResourceOperationStatus;
31 import static org.onap.so.adapters.nssmf.enums.JobStatus.PROCESSING;
32 import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
34 public abstract class InternalNssmfManager extends BaseNssmfManager {
37 protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
38 return doWrapAllocateReqBody(nbiRequest);
41 protected abstract String doWrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
44 protected String wrapReqBody(Object object) throws ApplicationException {
45 NssmfRequest nssmfRequest = new NssmfRequest(serviceInfo, esrInfo.getNetworkType(), object);
46 return marshal(nssmfRequest);
51 protected String wrapActDeActReqBody(ActDeActNssi actDeActNssi) throws ApplicationException {
53 return wrapReqBody(actDeActNssi);
58 protected String wrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
59 return wrapReqBody(deAllocateNssi);
64 protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
65 return responseDBStatus(status);
68 private RestResponse responseDBStatus(ResourceOperationStatus status) throws ApplicationException {
69 ResponseDescriptor descriptor = new ResponseDescriptor();
71 descriptor.setProgress(0);
72 descriptor.setStatus(PROCESSING.name());
73 descriptor.setStatusDescription("Initiating Nssi Instance");
74 return restUtil.createResponse(200, marshal(descriptor));
76 descriptor.setStatus(status.getStatus());
77 descriptor.setStatusDescription(status.getStatusDescription());
78 descriptor.setProgress(Integer.parseInt(status.getProgress()));
79 descriptor.setNssiId(status.getResourceInstanceID());
80 // descriptor.setResponseId(status.getOperationId());
81 return restUtil.createResponse(200, marshal(descriptor));
85 protected RestResponse sendRequest(String content) {
86 return sendInternalRequest(content);
90 protected void afterRequest() {
95 protected void afterQueryJobStatus(ResourceOperationStatus status) {
100 private RestResponse sendInternalRequest(String content) {
101 Header header = new BasicHeader("X-Auth-Token", adapterConfig.getInfraAuth());
102 this.nssmfUrl = adapterConfig.getInfraEndpoint() + this.nssmfUrl;
103 return restUtil.send(this.nssmfUrl, this.httpMethod, content, header);
107 protected String getApiVersion() {
108 return NssmfAdapterConsts.CURRENT_INTERNAL_NSSMF_API_VERSION;
113 protected SelectionType doQueryNSSISelectionCapability() {
114 return SelectionType.NSSMF;
118 protected String wrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
119 return doWrapModifyReqBody(nbiRequest);
122 protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
125 protected RestResponse doQuerySubnetCapability(String req) throws ApplicationException {
127 return sendRequest(req);