aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfAdapterRest.java
blob: d8e1e36058d6020b21a454a43c96370d851812a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.adapters.nssmf.rest;

import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
import org.onap.so.beans.nsmf.JobStatusRequest;
import org.onap.so.beans.nsmf.NssiActDeActRequest;
import org.onap.so.beans.nsmf.NssiAllocateRequest;
import org.onap.so.beans.nsmf.NssiCreateRequest;
import org.onap.so.beans.nsmf.NssiDeAllocateRequest;
import org.onap.so.beans.nsmf.NssiTerminateRequest;
import org.onap.so.beans.nsmf.NssiUpdateRequest;
import org.onap.so.beans.nsmf.NssiUpdateRequestById;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.assertObjectNotNull;

@Controller
@RequestMapping(value = "/api/rest/provMns/v1", produces = {APPLICATION_JSON}, consumes = {APPLICATION_JSON})
public class NssmfAdapterRest {

    private static final Logger logger = LoggerFactory.getLogger(NssmfAdapterRest.class);

    @Autowired
    private NssmfManager nssmfMgr;

    @PostMapping(value = "/NSS/SliceProfiles")
    public ResponseEntity allocateNssi(@RequestBody NssiAllocateRequest allocate) {
        try {
            logger.info("Nssmi allocate request is invoked");
            assertObjectNotNull(allocate);
            RestResponse rsp = getNssmfMgr().allocateNssi(allocate);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/nssi")
    public ResponseEntity createNssi(@RequestBody NssiCreateRequest create) {
        try {
            logger.info("Nssmf create request is invoked");
            assertObjectNotNull(create);
            RestResponse rsp = getNssmfMgr().createNssi(create);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/SliceProfiles/{sliceProfileId}")
    public ResponseEntity deAllocateNssi(@RequestBody NssiDeAllocateRequest deAllocate,
            @PathVariable("sliceProfileId") final String sliceId) {
        try {
            logger.info("Nssmf deallocate request is invoked");
            assertObjectNotNull(deAllocate);
            RestResponse rsp = getNssmfMgr().deAllocateNssi(deAllocate, sliceId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/nssi/{nssiId}")
    public ResponseEntity terminateNssi(@RequestBody NssiTerminateRequest terminate,
            @PathVariable("nssiId") String nssiId) {
        try {
            logger.info("Nssmf terminate request is invoked");
            assertObjectNotNull(terminate);
            RestResponse rsp = getNssmfMgr().terminateNssi(terminate, nssiId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PutMapping(value = "/NSS/SliceProfiles/{sliceProfileId}")
    public ResponseEntity modifyNssi(@RequestBody NssiUpdateRequest update,
            @PathVariable("sliceProfileId") String sliceId) {
        try {
            logger.info("Nssmf modify request is invoked");
            assertObjectNotNull(update);
            RestResponse rsp = getNssmfMgr().updateNssi(update, sliceId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PutMapping(value = "/NSS/nssi/{nssiId}")
    public ResponseEntity modifyNssiById(@RequestBody NssiUpdateRequestById updateById,
            @PathVariable("nssiId") String nssiId) {
        try {
            logger.info("Nssmf modify by ID request is invoked");
            assertObjectNotNull(updateById);
            RestResponse rsp = getNssmfMgr().updateNssiById(updateById, nssiId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/{snssai}/activation")
    public ResponseEntity activateNssi(@RequestBody NssiActDeActRequest activate,
            @PathVariable("snssai") String snssai) {
        try {
            logger.info("Nssmf activate request is invoked");
            assertObjectNotNull(activate);
            RestResponse rsp = getNssmfMgr().activateNssi(activate, snssai);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/{snssai}/deactivation")
    public ResponseEntity deactivateNssi(@RequestBody NssiActDeActRequest deActivate,
            @PathVariable("snssai") String snssai) {
        try {
            logger.info("Nssmf activate request is invoked");
            assertObjectNotNull(deActivate);
            RestResponse rsp = getNssmfMgr().deActivateNssi(deActivate, snssai);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @PostMapping(value = "/NSS/jobs/{jobId}")
    public ResponseEntity queryJobStatus(@RequestBody JobStatusRequest jobStatusReq,
            @PathVariable("jobId") String jobId) {
        try {
            logger.info("Nssmf query job status request is invoked");
            assertObjectNotNull(jobStatusReq);
            RestResponse rsp = getNssmfMgr().queryJobStatus(jobStatusReq, jobId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @GetMapping(value = "/vendor/{vendorName}/type/{networkType}/NSS" + "/SliceProfiles/{sliceProfileId}")
    public ResponseEntity queryNssi(@PathVariable("vendorName") String vendorName,
            @PathVariable("networktype") String networkType, @PathVariable("sliceProfileId") String sliceId) {
        try {
            logger.info("Nssmf query nssi request is invoked");
            RestResponse rsp = getNssmfMgr().queryNssi(vendorName, networkType, sliceId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    @GetMapping(value = "/vendor/{vendorName}/type/{networkType}/NSS/nssi" + "/{nssiId}")
    public ResponseEntity queryNssiById(@PathVariable("vendorName") String vendorName,
            @PathVariable("networkTtype") String networkType, @PathVariable("nssiId") String nssiId) {
        try {
            logger.info("Nssmf query nssi by ID request is invoked");
            RestResponse rsp = getNssmfMgr().queryNssiById(vendorName, networkType, nssiId);
            return buildResponse(rsp);
        } catch (ApplicationException e) {
            return e.buildErrorResponse();
        }
    }

    public void setNssmfMgr(NssmfManager nssmfMgr) {
        this.nssmfMgr = nssmfMgr;
    }

    public NssmfManager getNssmfMgr() {
        return nssmfMgr;
    }

    private ResponseEntity buildResponse(RestResponse rsp) {
        return ResponseEntity.status(rsp.getStatus()).body(rsp.getResponseContent());
    }
}