summaryrefslogtreecommitdiffstats
path: root/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/resources/DriverResource.java
blob: 0c75e311e24916ec6ee32bb351adf133438634c5 (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
206
207
208
209
210
211
212
213
214
/**
 * Copyright 2016 ZTE Corporation.
 *
 * 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.
 */
package org.onap.sfc.resources;

import com.codahale.metrics.annotation.Timed;
import org.onap.sfc.entity.FlowClassifierReq4S;
import org.onap.sfc.entity.PortChainReq4S;
import org.onap.sfc.entity.PortPairGroupReq4N;
import org.onap.sfc.entity.PortPairGroupReq4S;
import org.onap.sfc.entity.portpair.PortPairReq4N;
import org.onap.sfc.entity.portpair.PortPairReq4S;
import org.onap.sfc.utils.SfcDriverUtil;
import org.onap.sfc.wrapper.N2sReqWrapper;
import org.onap.sfc.entity.DelReqInfo;
import org.onap.sfc.entity.FlowClassfierReq4N;
import org.onap.sfc.entity.PortChainReq4N;
import org.onap.sfc.entity.Result;
import org.onap.sfc.service.SdnServiceConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.DELETE;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/")
public class DriverResource {
    private static final Logger LOGGER = LoggerFactory.getLogger(DriverResource.class);
//
//    @POST
//    @Path("/checksdncontroller")
//    @Produces(MediaType.APPLICATION_JSON)
//    @Timed
//    public Result checkSdnController(SdnControllerInfo sdnInfo)
//            throws Exception {
//        if (sdnInfo == null ) {
//            throw new NotFoundException("SdnControllerInfo is null");
//        }
//        return SdnServiceConsumer.getSdnConProxy(sdnInfo.getUrl()).querySdnController();
//    }

    @POST
    @Path("/createportpair")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public Result createPortPair(PortPairReq4N portPairReq4N)
            throws Exception {
        if (portPairReq4N == null) {
            throw new NotFoundException("SdnControllerInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(portPairReq4N));
        PortPairReq4S portPairReq = N2sReqWrapper.convertPortPair(portPairReq4N);
        String portPairReqJson = SfcDriverUtil.toJson(portPairReq);
        LOGGER.info(portPairReqJson);
        SdnServiceConsumer.getSdnConProxy(portPairReq4N.getUrl()).createPortPair(SfcDriverUtil.generateAuthorization(), portPairReqJson);
//
//        if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
//        {
//            return new Result(portPairReq.getPortPair().get(0).getUuid());
//        }
//        return rsp;

        return new Result(portPairReq.getPortPair().get(0).getUuid());
    }

    @POST
    @Path("/createportpairgroup")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public Result createPortPairGroup(PortPairGroupReq4N portPairGroupReq4N)
            throws Exception {
        if (portPairGroupReq4N == null) {
            throw new NotFoundException("SdnControllerInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(portPairGroupReq4N));
        PortPairGroupReq4S portPairGroupReq4S = N2sReqWrapper.convertPortPairGroup(portPairGroupReq4N);
        String portPairGroupReqJson = SfcDriverUtil.toJson(portPairGroupReq4S);
        LOGGER.info(portPairGroupReqJson);
        SdnServiceConsumer.getSdnConProxy(portPairGroupReq4N.getUrl()).createPortPairGroup(
                SfcDriverUtil.generateAuthorization(), portPairGroupReqJson);
//        if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
//        {
//            return new Result(portPairGroupReq4S.getPortPairGroupReqs().get(0).getUuid());
//        }
//
//        return rsp;

        return new Result(portPairGroupReq4S.getPortPairGroupReqs().get(0).getUuid());

    }

    @POST
    @Path("/createflowclassfier")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public Result createFlowClassfier(FlowClassfierReq4N flowClassfierReq4N)
            throws Exception {
        if (flowClassfierReq4N == null) {
            throw new NotFoundException("FlowClassfierReq4N is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(flowClassfierReq4N));
        FlowClassifierReq4S flowClassfierReq4S = N2sReqWrapper.
                convertFlowClassfier(flowClassfierReq4N);
        String uuid = flowClassfierReq4S.getSfcFlowClassifier().get(0).getUuid();
        String flowClassifierJson = SfcDriverUtil.toJson(flowClassfierReq4S);
        LOGGER.info(flowClassifierJson);
        SdnServiceConsumer.getSdnConProxy(flowClassfierReq4N.getUrl()).createFlowCla(SfcDriverUtil.generateAuthorization(), flowClassifierJson);
//        if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
//        {
//            return new Result(uuid);
//        }
//        else
//            return rsp;

        return new Result(uuid);
    }

    @POST
    @Path("/createportchain")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public Result creatPortChain(PortChainReq4N portChainReq4N)
            throws Exception {
        if (portChainReq4N == null) {
            throw new NotFoundException("PortChainReq4N is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(portChainReq4N));
        PortChainReq4S portChainReq = N2sReqWrapper.converPortChain(portChainReq4N);
        String portChainReqJson = SfcDriverUtil.toJson(portChainReq);
        LOGGER.info(portChainReqJson);
        SdnServiceConsumer.getSdnConProxy(portChainReq4N.getUrl()).createPortChain(
                SfcDriverUtil.generateAuthorization(), portChainReqJson);
//        if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
//        {
//            return new Result(portChainReq.getPortChainReqs().get(0).getUuid());
//        }
//        return rsp;

        return new Result(portChainReq.getPortChainReqs().get(0).getUuid());

    }

    @DELETE
    @Path("/delportpair")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public void delPortPair(DelReqInfo delReqInfo)
            throws Exception {
        if (delReqInfo == null) {
            throw new NotFoundException("DelReqInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
        SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortPair(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());

    }

    @DELETE
    @Path("/delportpairgroup")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public void delPortPairGroup(DelReqInfo delReqInfo)
            throws Exception {
        if (delReqInfo == null) {
            throw new NotFoundException("DelReqInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
        SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortPairGroup(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());

    }

    @DELETE
    @Path("/delclassifier")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public void delFlowClassfier(DelReqInfo delReqInfo)
            throws Exception {
        if (delReqInfo == null) {
            throw new NotFoundException("DelReqInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
        SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deleteFlowClassifiers(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());

    }

    @DELETE
    @Path("/delchain")
    @Produces(MediaType.APPLICATION_JSON)
    @Timed
    public void delPortChain(DelReqInfo delReqInfo)
            throws Exception {
        if (delReqInfo == null) {
            throw new NotFoundException("DelReqInfo is null");
        }
        LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
        SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortChain(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());

    }
}