2 * Copyright (c) 2012-2013 NEC Corporation
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this
7 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.vtn.javaapi.resources.logical;
11 import java.util.ArrayList;
12 import java.util.List;
14 import com.google.gson.JsonNull;
15 import com.google.gson.JsonObject;
16 import org.opendaylight.vtn.core.ipc.ClientSession;
17 import org.opendaylight.vtn.core.util.Logger;
18 import org.opendaylight.vtn.javaapi.annotation.UNCField;
19 import org.opendaylight.vtn.javaapi.annotation.UNCVtnService;
20 import org.opendaylight.vtn.javaapi.constants.VtnServiceConsts;
21 import org.opendaylight.vtn.javaapi.constants.VtnServiceJsonConsts;
22 import org.opendaylight.vtn.javaapi.exception.VtnServiceException;
23 import org.opendaylight.vtn.javaapi.ipc.IpcRequestProcessor;
24 import org.opendaylight.vtn.javaapi.ipc.conversion.IpcDataUnitWrapper;
25 import org.opendaylight.vtn.javaapi.ipc.conversion.IpcLogicalResponseFactory;
26 import org.opendaylight.vtn.javaapi.ipc.enums.IpcRequestPacketEnum;
27 import org.opendaylight.vtn.javaapi.ipc.enums.UncCommonEnum;
28 import org.opendaylight.vtn.javaapi.ipc.enums.UncCommonEnum.UncResultCode;
29 import org.opendaylight.vtn.javaapi.ipc.enums.UncJavaAPIErrorCode;
30 import org.opendaylight.vtn.javaapi.ipc.enums.UncOption2Enum;
31 import org.opendaylight.vtn.javaapi.ipc.enums.UncUPLLEnums;
32 import org.opendaylight.vtn.javaapi.resources.AbstractResource;
33 import org.opendaylight.vtn.javaapi.validation.logical.InterfaceResourceValidator;
36 * The Class VBypassInterfaceResource.
38 /* This class handles put, delete and get methods */
39 @UNCVtnService(path = "/vtns/{vtn_name}/vbypasses/{vbypass_name}/interfaces/{if_name}")
40 public class VBypassInterfaceResource extends AbstractResource {
43 private String vtnName;
44 /** The vbypass name. */
45 @UNCField("vbypass_name")
46 private String vbypassName;
47 /** The interface name. */
49 private String ifName;
53 * @return the vtn name
55 public String getVtnName() {
59 * Gets the vbypass name.
61 * @return the vbypass name
63 public String getVbypassName() {
71 public String getIfName() {
74 private static final Logger LOG = Logger
75 .getLogger(VBypassInterfaceResource.class.getName());
77 * Instantiates a new VBypass interface resource.
79 public VBypassInterfaceResource() {
81 LOG.trace("Start VBypassInterfaceResource#VBypassInterfacesResource()");
82 setValidator(new InterfaceResourceValidator(this));
83 LOG.trace("Completed VBypassInterfaceResource#VBypassInterfacesResource()");
86 * Implementation of Put method of VBypass Interface API
89 * the request Json object
92 * @throws VtnServiceException
95 public int put(final JsonObject requestBody) throws VtnServiceException {
96 LOG.trace("Starts VBypassInterfaceResource#put()");
97 ClientSession session = null;
98 IpcRequestProcessor requestProcessor = null;
99 int status = ClientSession.RESP_FATAL;
101 LOG.debug("Start Ipc framework call");
102 session = getConnPool().getSession(
103 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
104 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
105 UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),
106 getExceptionHandler());
107 LOG.debug("Session created successfully");
108 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
109 getConfigID(), getExceptionHandler());
110 requestProcessor.createIpcRequestPacket(
111 IpcRequestPacketEnum.KT_VUNK_IF_UPDATE, requestBody,
113 status = requestProcessor.processIpcRequest();
114 LOG.debug("Request packet processed with status" + status);
115 LOG.debug("Complete Ipc framework call");
116 } catch (final VtnServiceException e) {
117 getExceptionHandler()
118 .raise(Thread.currentThread().getStackTrace()[1]
120 + VtnServiceConsts.HYPHEN
121 + Thread.currentThread().getStackTrace()[1]
123 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
124 UncJavaAPIErrorCode.IPC_SERVER_ERROR
125 .getErrorMessage(), e);
128 if (status == ClientSession.RESP_FATAL) {
129 if (null != requestProcessor.getErrorJson()) {
130 setInfo(requestProcessor.getErrorJson());
132 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
135 status = UncResultCode.UNC_SERVER_ERROR.getValue();
137 getConnPool().destroySession(session);
139 LOG.trace("Completed VBypassInterfaceResource#put()");
143 * Implementation of Delete method of VBypass Interface API
146 * @throws VtnServiceException
149 public int delete() throws VtnServiceException {
150 LOG.trace("starts VBypassInterfaceResource#delete()");
151 ClientSession session = null;
152 IpcRequestProcessor requestProcessor = null;
153 int status = ClientSession.RESP_FATAL;
155 LOG.debug("Start Ipc framework call");
156 session = getConnPool().getSession(
157 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
158 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
159 UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),
160 getExceptionHandler());
161 LOG.debug("Session created successfully");
162 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
163 getConfigID(), getExceptionHandler());
164 requestProcessor.createIpcRequestPacket(
165 IpcRequestPacketEnum.KT_VUNK_IF_DELETE,
166 getNullJsonObject(), getUriParameters());
167 status = requestProcessor.processIpcRequest();
168 LOG.debug("Request packet processed with status" + status);
169 LOG.debug("Complete Ipc framework call");
170 } catch (final VtnServiceException e) {
171 getExceptionHandler()
172 .raise(Thread.currentThread().getStackTrace()[1]
174 + VtnServiceConsts.HYPHEN
175 + Thread.currentThread().getStackTrace()[1]
177 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
178 UncJavaAPIErrorCode.IPC_SERVER_ERROR
179 .getErrorMessage(), e);
182 if (status == ClientSession.RESP_FATAL) {
183 if (null != requestProcessor.getErrorJson()) {
184 setInfo(requestProcessor.getErrorJson());
186 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
189 status = UncResultCode.UNC_SERVER_ERROR.getValue();
191 getConnPool().destroySession(session);
193 LOG.trace("Completed VBypassInterfaceResource#delete()");
197 * Implementation of get method of VBypass Interface API
200 * the request Json object
203 * @throws VtnServiceException
206 public int get(final JsonObject requestBody) throws VtnServiceException {
207 LOG.trace("Starts VBypassInterfaceResource#get()");
208 ClientSession session = null;
209 IpcRequestProcessor requestProcessor = null;
210 int status = ClientSession.RESP_FATAL;
212 LOG.debug("Start Ipc framework call");
213 session = getConnPool().getSession(
214 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
215 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
216 UncUPLLEnums.ServiceID.UPLL_READ_SVC_ID.ordinal(),
217 getExceptionHandler());
218 LOG.debug("Session created successfully");
219 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
220 getConfigID(), getExceptionHandler());
221 requestProcessor.createIpcRequestPacket(
222 IpcRequestPacketEnum.KT_VUNK_IF_GET, requestBody,
224 LOG.debug("Request packet created successfully for 1st request");
225 status = requestProcessor.processIpcRequest();
226 LOG.debug("Request packet processed for 1st call with status" + status);
227 if (status == ClientSession.RESP_FATAL) {
228 throw new VtnServiceException(
229 Thread.currentThread().getStackTrace()[1]
231 + VtnServiceConsts.HYPHEN
232 + Thread.currentThread().getStackTrace()[1]
234 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
235 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
237 JsonObject neighbor = null;
238 JsonObject vbypassInterfaceJson = null;
239 IpcLogicalResponseFactory responseGenerator = new IpcLogicalResponseFactory();
240 String dataType = null;
241 if (requestBody.has(VtnServiceJsonConsts.TARGETDB)) {
242 dataType = requestBody.get(VtnServiceJsonConsts.TARGETDB)
245 vbypassInterfaceJson = responseGenerator.getVBypassInterfaceResponse(
246 requestProcessor.getIpcResponsePacket(), requestBody,
247 VtnServiceJsonConsts.SHOW);
248 if (VtnServiceJsonConsts.STATE.equalsIgnoreCase(dataType) && !(vbypassInterfaceJson.get(VtnServiceJsonConsts.INTERFACE) instanceof JsonNull)) {
249 requestProcessor.setServiceInfo(
250 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
251 UncUPLLEnums.ServiceID.UPLL_READ_SVC_ID.ordinal());
252 requestProcessor.createIpcRequestPacket(
253 IpcRequestPacketEnum.KT_VUNK_IF_GET, requestBody,
259 .setIpcUint32Value(UncOption2Enum.UNC_OPT2_NEIGHBOR
261 LOG.debug("Request packet created successfully for 2nd request");
262 status = requestProcessor.processIpcRequest();
263 LOG.debug("Request packet for 2nd request processed with status" + status);
264 neighbor = responseGenerator.getNeighborResponse(
265 requestProcessor.getIpcResponsePacket(), requestBody,
266 VtnServiceJsonConsts.SHOW);
267 vbypassInterfaceJson.get(VtnServiceJsonConsts.INTERFACE)
269 .add(VtnServiceJsonConsts.NEIGHBOR, neighbor);
271 setInfo(vbypassInterfaceJson);
272 LOG.debug("Response object created successfully");
273 LOG.debug("Complete Ipc framework call");
274 } catch (final VtnServiceException e) {
275 getExceptionHandler()
276 .raise(Thread.currentThread().getStackTrace()[1]
278 + VtnServiceConsts.HYPHEN
279 + Thread.currentThread().getStackTrace()[1]
281 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
282 UncJavaAPIErrorCode.IPC_SERVER_ERROR
283 .getErrorMessage(), e);
286 if (status == ClientSession.RESP_FATAL) {
287 if (null != requestProcessor.getErrorJson()) {
288 setInfo(requestProcessor.getErrorJson());
290 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
293 status = UncResultCode.UNC_SERVER_ERROR.getValue();
295 getConnPool().destroySession(session);
297 LOG.trace("Completed VBypassInterfaceResource#get()");
301 * Add URI parameters to list
303 * @return parameter list
305 private List<String> getUriParameters() {
306 LOG.trace("Start VBypassInterfaceResource#getUriParameters()");
307 List<String> uriParameters = new ArrayList<String>();
308 uriParameters.add(vtnName);
309 uriParameters.add(vbypassName);
310 uriParameters.add(ifName);
311 LOG.trace("Completed VBypassInterfaceResource#getUriParameters()");
312 return uriParameters;