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.JsonObject;
15 import org.opendaylight.vtn.core.ipc.ClientSession;
16 import org.opendaylight.vtn.core.util.Logger;
17 import org.opendaylight.vtn.javaapi.annotation.UNCField;
18 import org.opendaylight.vtn.javaapi.annotation.UNCVtnService;
19 import org.opendaylight.vtn.javaapi.constants.VtnServiceConsts;
20 import org.opendaylight.vtn.javaapi.constants.VtnServiceJsonConsts;
21 import org.opendaylight.vtn.javaapi.exception.VtnServiceException;
22 import org.opendaylight.vtn.javaapi.ipc.IpcRequestProcessor;
23 import org.opendaylight.vtn.javaapi.ipc.conversion.IpcDataUnitWrapper;
24 import org.opendaylight.vtn.javaapi.ipc.conversion.IpcLogicalResponseFactory;
25 import org.opendaylight.vtn.javaapi.ipc.enums.IpcRequestPacketEnum;
26 import org.opendaylight.vtn.javaapi.ipc.enums.UncCommonEnum;
27 import org.opendaylight.vtn.javaapi.ipc.enums.UncCommonEnum.UncResultCode;
28 import org.opendaylight.vtn.javaapi.ipc.enums.UncJavaAPIErrorCode;
29 import org.opendaylight.vtn.javaapi.ipc.enums.UncOperationEnum;
30 import org.opendaylight.vtn.javaapi.ipc.enums.UncOption1Enum;
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.VBridgeFlowFilterEntryResourceValidator;
36 * The Class VBridgeInterfaceFlowFilterEntryResource implements delete, put and
40 @UNCVtnService(path = "/vtns/{vtn_name}/vbridges/{vbr_name}/interfaces/{if_name}/flowfilters/{ff_type}/flowfilterentries/{seqnum}")
41 public class VBridgeInterfaceFlowFilterEntryResource extends AbstractResource {
45 private String vtnName;
48 private String vbrName;
51 private String ifName;
54 private String ffType;
55 /** The Sequence Number. */
57 private String seqnum;
59 /** The Constant LOG. */
60 private static final Logger LOG = Logger
61 .getLogger(VBridgeInterfaceFlowFilterEntryResource.class
65 * Instantiates a new v bridge interface flow filter entry resource.
67 public VBridgeInterfaceFlowFilterEntryResource() {
69 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#VBridgeInterfaceFlowFilterEntryResource()");
70 setValidator(new VBridgeFlowFilterEntryResourceValidator(this));
71 LOG.trace("Completed VBridgeInterfaceFlowFilterEntryResource#VBridgeInterfaceFlowFilterEntryResource()");
77 public String getVtnName() {
84 public String getVbrName() {
91 public String getIfName() {
98 public String getFfType() {
105 public String getSeqnum() {
110 * Implementation of Put method of VBridgeInterfaceFlowFilterEntry API
113 * the request Json object
116 * @throws VtnServiceException
119 public int put(final JsonObject requestBody) throws VtnServiceException {
120 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#put()");
121 ClientSession session = null;
122 IpcRequestProcessor requestProcessor = null;
123 int status = ClientSession.RESP_FATAL;
125 LOG.debug("Start Ipc framework call");
126 session = getConnPool().getSession(
127 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
128 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
129 UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),
130 getExceptionHandler());
131 LOG.debug("Session created successfully");
132 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
133 getConfigID(), getExceptionHandler());
134 requestProcessor.createIpcRequestPacket(
135 IpcRequestPacketEnum.KT_VBRIF_FLOWFILTER_ENTRY_UPDATE,
136 requestBody, getUriParameters());
137 LOG.debug("Request packet created successfully");
138 status = requestProcessor.processIpcRequest();
139 LOG.debug("Request packet processed with status" + status);
140 LOG.debug("Complete Ipc framework call");
141 } catch (final VtnServiceException e) {
142 getExceptionHandler()
143 .raise(Thread.currentThread().getStackTrace()[1]
145 + VtnServiceConsts.HYPHEN
146 + Thread.currentThread().getStackTrace()[1]
148 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
149 UncJavaAPIErrorCode.IPC_SERVER_ERROR
150 .getErrorMessage(), e);
153 if (status == ClientSession.RESP_FATAL) {
154 if (null != requestProcessor.getErrorJson()) {
155 setInfo(requestProcessor.getErrorJson());
157 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
160 status = UncResultCode.UNC_SERVER_ERROR.getValue();
162 getConnPool().destroySession(session);
164 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#put()");
169 * Implementation of Delete method of VBridgeInterfaceFlowFilterEntry API
173 * @throws VtnServiceException
176 public int delete() throws VtnServiceException {
177 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#delete()");
178 ClientSession session = null;
179 IpcRequestProcessor requestProcessor = null;
180 int status = ClientSession.RESP_FATAL;
182 LOG.debug("Start Ipc framework call");
183 session = getConnPool().getSession(
184 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
185 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
186 UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),
187 getExceptionHandler());
188 LOG.debug("Session created successfully");
189 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
190 getConfigID(), getExceptionHandler());
191 requestProcessor.createIpcRequestPacket(
192 IpcRequestPacketEnum.KT_VBRIF_FLOWFILTER_ENTRY_DELETE,
193 getNullJsonObject(), getUriParameters());
194 LOG.debug("Request packet created successfully");
195 status = requestProcessor.processIpcRequest();
196 LOG.debug("Request packet processed with status" + status);
197 LOG.debug("Complete Ipc framework call");
198 } catch (final VtnServiceException e) {
199 getExceptionHandler()
200 .raise(Thread.currentThread().getStackTrace()[1]
202 + VtnServiceConsts.HYPHEN
203 + Thread.currentThread().getStackTrace()[1]
205 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
206 UncJavaAPIErrorCode.IPC_SERVER_ERROR
207 .getErrorMessage(), e);
210 if (status == ClientSession.RESP_FATAL) {
211 if (null != requestProcessor.getErrorJson()) {
212 setInfo(requestProcessor.getErrorJson());
214 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
217 status = UncResultCode.UNC_SERVER_ERROR.getValue();
219 getConnPool().destroySession(session);
221 LOG.trace("Completed VBridgeInterfaceFlowFilterEntryResource#delete()");
226 * Implementation of Get method of VBridgeInterfaceFlowFilterEntry API
229 * the request Json object
232 * @throws VtnServiceException
235 public int get(final JsonObject requestBody) throws VtnServiceException {
236 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#get()");
237 ClientSession session = null;
238 IpcRequestProcessor requestProcessor = null;
239 int status = ClientSession.RESP_FATAL;
241 LOG.debug("Start Ipc framework call");
242 session = getConnPool().getSession(
243 UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,
244 UncUPLLEnums.UPLL_IPC_SERVICE_NAME,
245 UncUPLLEnums.ServiceID.UPLL_READ_SVC_ID.ordinal(),
246 getExceptionHandler());
247 LOG.debug("Session created successfully");
248 requestProcessor = new IpcRequestProcessor(session, getSessionID(),
249 getConfigID(), getExceptionHandler());
250 requestProcessor.createIpcRequestPacket(
251 IpcRequestPacketEnum.KT_VBRIF_FLOWFILTER_ENTRY_GET,
252 requestBody, getUriParameters());
253 requestProcessor.getRequestPacket().setOperation(
255 .setIpcUint32Value(UncOperationEnum.UNC_OP_READ
257 if (!requestBody.has(VtnServiceJsonConsts.TARGETDB)
258 || (requestBody.has(VtnServiceJsonConsts.TARGETDB) && requestBody
259 .get(VtnServiceJsonConsts.TARGETDB).getAsString()
260 .equalsIgnoreCase(VtnServiceJsonConsts.STATE))) {
265 .setIpcUint32Value((UncOption1Enum.UNC_OPT1_DETAIL
268 LOG.debug("Request packet created successfully");
269 status = requestProcessor.processIpcRequest();
270 LOG.debug("Request packet processed with status" + status);
271 final IpcLogicalResponseFactory responseGenerator = new IpcLogicalResponseFactory();
272 setInfo(responseGenerator
273 .getVBridgeInterfaceFlowFilterEntryResponse(
274 requestProcessor.getIpcResponsePacket(),
275 requestBody, VtnServiceJsonConsts.SHOW));
276 LOG.debug("Response object created successfully");
277 LOG.debug("Complete Ipc framework call");
278 } catch (final VtnServiceException e) {
279 getExceptionHandler()
280 .raise(Thread.currentThread().getStackTrace()[1]
282 + VtnServiceConsts.HYPHEN
283 + Thread.currentThread().getStackTrace()[1]
285 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
286 UncJavaAPIErrorCode.IPC_SERVER_ERROR
287 .getErrorMessage(), e);
290 if (status == ClientSession.RESP_FATAL) {
291 if (null != requestProcessor
292 && null != requestProcessor.getErrorJson()) {
293 setInfo(requestProcessor.getErrorJson());
295 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR
298 status = UncResultCode.UNC_SERVER_ERROR.getValue();
300 getConnPool().destroySession(session);
302 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#get()");
307 * Add URI parameters to list
309 * @return parameter list
311 private List<String> getUriParameters() {
312 LOG.trace("Start VBridgeInterfaceFlowFilterEntryResource#getUriParameters()");
313 final List<String> uriParameters = new ArrayList<String>();
314 uriParameters.add(vtnName);
315 uriParameters.add(vbrName);
316 uriParameters.add(ifName);
317 uriParameters.add(ffType);
318 uriParameters.add(seqnum);
319 LOG.trace("Completed VBridgeInterfaceFlowFilterEntryResource#getUriParameters()");
320 return uriParameters;