2 * Copyright 2016 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.sfc.resources;
18 import com.codahale.metrics.annotation.Timed;
19 import org.openo.sfc.entity.DelReqInfo;
20 import org.openo.sfc.entity.FlowClassfierReq4N;
21 import org.openo.sfc.entity.FlowClassifierReq4S;
22 import org.openo.sfc.entity.PortChainReq4N;
23 import org.openo.sfc.entity.PortChainReq4S;
24 import org.openo.sfc.entity.PortPairGroupReq4N;
25 import org.openo.sfc.entity.PortPairGroupReq4S;
26 import org.openo.sfc.entity.Result;
27 import org.openo.sfc.entity.portpair.PortPairReq4N;
28 import org.openo.sfc.entity.portpair.PortPairReq4S;
29 import org.openo.sfc.service.SdnServiceConsumer;
30 import org.openo.sfc.utils.SfcDriverUtil;
31 import org.openo.sfc.wrapper.N2sReqWrapper;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import javax.ws.rs.DELETE;
36 import javax.ws.rs.NotFoundException;
37 import javax.ws.rs.POST;
38 import javax.ws.rs.Path;
39 import javax.ws.rs.Produces;
40 import javax.ws.rs.core.MediaType;
43 public class DriverResource {
44 private static final Logger LOGGER = LoggerFactory.getLogger(DriverResource.class);
47 // @Path("/checksdncontroller")
48 // @Produces(MediaType.APPLICATION_JSON)
50 // public Result checkSdnController(SdnControllerInfo sdnInfo)
52 // if (sdnInfo == null ) {
53 // throw new NotFoundException("SdnControllerInfo is null");
55 // return SdnServiceConsumer.getSdnConProxy(sdnInfo.getUrl()).querySdnController();
59 @Path("/createportpair")
60 @Produces(MediaType.APPLICATION_JSON)
62 public Result createPortPair(PortPairReq4N portPairReq4N)
64 if (portPairReq4N == null) {
65 throw new NotFoundException("SdnControllerInfo is null");
67 LOGGER.info(SfcDriverUtil.toJson(portPairReq4N));
68 PortPairReq4S portPairReq = N2sReqWrapper.convertPortPair(portPairReq4N);
69 String portPairReqJson = SfcDriverUtil.toJson(portPairReq);
70 LOGGER.info(portPairReqJson);
71 SdnServiceConsumer.getSdnConProxy(portPairReq4N.getUrl()).createPortPair(SfcDriverUtil.generateAuthorization(), portPairReqJson);
73 // if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
75 // return new Result(portPairReq.getPortPair().get(0).getUuid());
79 return new Result(portPairReq.getPortPair().get(0).getUuid());
83 @Path("/createportpairgroup")
84 @Produces(MediaType.APPLICATION_JSON)
86 public Result createPortPairGroup(PortPairGroupReq4N portPairGroupReq4N)
88 if (portPairGroupReq4N == null) {
89 throw new NotFoundException("SdnControllerInfo is null");
91 LOGGER.info(SfcDriverUtil.toJson(portPairGroupReq4N));
92 PortPairGroupReq4S portPairGroupReq4S = N2sReqWrapper.convertPortPairGroup(portPairGroupReq4N);
93 String portPairGroupReqJson = SfcDriverUtil.toJson(portPairGroupReq4S);
94 LOGGER.info(portPairGroupReqJson);
95 SdnServiceConsumer.getSdnConProxy(portPairGroupReq4N.getUrl()).createPortPairGroup(
96 SfcDriverUtil.generateAuthorization(), portPairGroupReqJson);
97 // if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
99 // return new Result(portPairGroupReq4S.getPortPairGroupReqs().get(0).getUuid());
104 return new Result(portPairGroupReq4S.getPortPairGroupReqs().get(0).getUuid());
109 @Path("/createflowclassfier")
110 @Produces(MediaType.APPLICATION_JSON)
112 public Result createFlowClassfier(FlowClassfierReq4N flowClassfierReq4N)
114 if (flowClassfierReq4N == null) {
115 throw new NotFoundException("FlowClassfierReq4N is null");
117 LOGGER.info(SfcDriverUtil.toJson(flowClassfierReq4N));
118 FlowClassifierReq4S flowClassfierReq4S = N2sReqWrapper.
119 convertFlowClassfier(flowClassfierReq4N);
120 String uuid = flowClassfierReq4S.getSfcFlowClassifier().get(0).getUuid();
121 String flowClassifierJson = SfcDriverUtil.toJson(flowClassfierReq4S);
122 LOGGER.info(flowClassifierJson);
123 SdnServiceConsumer.getSdnConProxy(flowClassfierReq4N.getUrl()).createFlowCla(SfcDriverUtil.generateAuthorization(), flowClassifierJson);
124 // if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
126 // return new Result(uuid);
131 return new Result(uuid);
135 @Path("/createportchain")
136 @Produces(MediaType.APPLICATION_JSON)
138 public Result creatPortChain(PortChainReq4N portChainReq4N)
140 if (portChainReq4N == null) {
141 throw new NotFoundException("PortChainReq4N is null");
143 LOGGER.info(SfcDriverUtil.toJson(portChainReq4N));
144 PortChainReq4S portChainReq = N2sReqWrapper.converPortChain(portChainReq4N);
145 String portChainReqJson = SfcDriverUtil.toJson(portChainReq);
146 LOGGER.info(portChainReqJson);
147 SdnServiceConsumer.getSdnConProxy(portChainReq4N.getUrl()).createPortChain(
148 SfcDriverUtil.generateAuthorization(), portChainReqJson);
149 // if(rsp.getStatus() == SfcConst.HTTP_POST_OK)
151 // return new Result(portChainReq.getPortChainReqs().get(0).getUuid());
155 return new Result(portChainReq.getPortChainReqs().get(0).getUuid());
160 @Path("/delportpair")
161 @Produces(MediaType.APPLICATION_JSON)
163 public void delPortPair(DelReqInfo delReqInfo)
165 if (delReqInfo == null) {
166 throw new NotFoundException("DelReqInfo is null");
168 LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
169 SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortPair(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());
174 @Path("/delportpairgroup")
175 @Produces(MediaType.APPLICATION_JSON)
177 public void delPortPairGroup(DelReqInfo delReqInfo)
179 if (delReqInfo == null) {
180 throw new NotFoundException("DelReqInfo is null");
182 LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
183 SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortPairGroup(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());
188 @Path("/delclassifier")
189 @Produces(MediaType.APPLICATION_JSON)
191 public void delFlowClassfier(DelReqInfo delReqInfo)
193 if (delReqInfo == null) {
194 throw new NotFoundException("DelReqInfo is null");
196 LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
197 SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deleteFlowClassifiers(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());
203 @Produces(MediaType.APPLICATION_JSON)
205 public void delPortChain(DelReqInfo delReqInfo)
207 if (delReqInfo == null) {
208 throw new NotFoundException("DelReqInfo is null");
210 LOGGER.info(SfcDriverUtil.toJson(delReqInfo));
211 SdnServiceConsumer.getSdnConProxy(delReqInfo.getUrl()).deletePortChain(SfcDriverUtil.generateAuthorization(), delReqInfo.getId());