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
10 package org.opendaylight.vtn.javaapi.resources.logical;
12 import java.util.ArrayList;
13 import java.util.List;
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.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.UncUPLLEnums;
30 import org.opendaylight.vtn.javaapi.resources.AbstractResource;
31 import org.opendaylight.vtn.javaapi.validation.logical.PortMapResourceValidator;
34 * The Class VTepInterfacePortMapResource implements delete, put and get methods.
38 @UNCVtnService(path = "/vtns/{vtn_name}/vteps/{vtep_name}/interfaces/{if_name}/portmap")
39 public class VTepInterfacePortMapResource extends AbstractResource {
42 private String vtnName;
44 @UNCField("vtep_name")
45 private String vtepName;
48 private String ifName;
50 /** The Constant LOG. */
51 private static final Logger LOG = Logger.getLogger(VTepInterfacePortMapResource.class.getSimpleName());
55 * @return the vtn name
57 public String getVtnName() {
63 * @return the vbr name
65 public String getVtepName() {
73 public String getIfName() {
77 * Instantiates a new port map resource.
79 public VTepInterfacePortMapResource() {
81 LOG.trace("Start VTepInterfacePortMapResource#VTepInterfacePortMapResource()");
82 setValidator(new PortMapResourceValidator(this));
83 LOG.trace("Complete VTepInterfacePortMapResource#VTepInterfacePortMapResource()");
87 * Implementation of Delete method of VTep Interface PortMap API
90 * @throws VtnServiceException
93 public int delete() throws VtnServiceException {
94 LOG.trace("Start VTepInterfacePortMapResource#delete()");
95 ClientSession session = null;
96 IpcRequestProcessor requestProcessor = null;
97 int status = ClientSession.RESP_FATAL;
99 session = getConnPool().getSession(UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,UncUPLLEnums.UPLL_IPC_SERVICE_NAME,UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),getExceptionHandler());
100 LOG.debug("Session created successfully");
101 requestProcessor = new IpcRequestProcessor(session, getSessionID(), getConfigID(),getExceptionHandler());
102 requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VTEP_IF_UPDATE,getNullJsonObject(),getUriParameters());
103 LOG.debug("Request packet created successfully");
104 status= requestProcessor.processIpcRequest();
105 } catch (final VtnServiceException e) {
106 getExceptionHandler().raise(
107 Thread.currentThread().getStackTrace()[1].getClassName()
108 + VtnServiceConsts.HYPHEN
109 + Thread.currentThread().getStackTrace()[1].getMethodName(),
110 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
111 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(), e);
114 if (status == ClientSession.RESP_FATAL) {
115 if(null != requestProcessor.getErrorJson()){
116 setInfo(requestProcessor.getErrorJson());
118 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
120 status = UncResultCode.UNC_SERVER_ERROR.getValue();
122 getConnPool().destroySession(session);
124 LOG.trace("Complete VTepInterfacePortMapResource#delete()");
128 * Implementation of get method of VTep Interface PortMap API
130 * @param requestBody the request Json object
133 * @throws VtnServiceException
136 public int get(final JsonObject requestBody) throws VtnServiceException {
137 LOG.trace("Start VTepInterfacePortMapResource#get()");
138 ClientSession session = null;
139 IpcRequestProcessor requestProcessor = null;
140 int status = ClientSession.RESP_FATAL;
142 session = getConnPool().getSession(UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,UncUPLLEnums.UPLL_IPC_SERVICE_NAME,UncUPLLEnums.ServiceID.UPLL_READ_SVC_ID.ordinal(),getExceptionHandler());
143 LOG.debug("Session created successfully");
144 requestProcessor = new IpcRequestProcessor(session, getSessionID(), getConfigID(),getExceptionHandler());
145 requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VTEP_IF_GET, requestBody,getUriParameters());
146 LOG.debug("Request Packet created successfully");
147 status= requestProcessor.processIpcRequest();
148 IpcLogicalResponseFactory responseGenerator = new IpcLogicalResponseFactory();
149 setInfo(responseGenerator.getPortMapResponse(requestProcessor.getIpcResponsePacket(),requestBody,VtnServiceJsonConsts.SHOW,VtnServiceJsonConsts.VTEP_INTERFACE_PORTMAP));
150 LOG.debug("response object created successfully");
151 LOG.debug("Ipc framework call complete");
152 } catch (final VtnServiceException e) {
153 getExceptionHandler().raise(
154 Thread.currentThread().getStackTrace()[1].getClassName()
155 + VtnServiceConsts.HYPHEN
156 + Thread.currentThread().getStackTrace()[1].getMethodName(),
157 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
158 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(), e);
161 if (status == ClientSession.RESP_FATAL) {
162 if(null != requestProcessor.getErrorJson()){
163 setInfo(requestProcessor.getErrorJson());
165 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
167 status = UncResultCode.UNC_SERVER_ERROR.getValue();
169 getConnPool().destroySession(session);
171 LOG.trace("Complete VTepInterfacePortMapResource#get()");
176 * Implementation of Put method of PortMap API
178 * @param requestBody the request Json object
181 * @throws VtnServiceException
184 public int put(final JsonObject requestBody) throws VtnServiceException {
185 LOG.trace("Start VTepInterfacePortMapResource#put()");
186 ClientSession session = null;
187 IpcRequestProcessor requestProcessor = null;
188 int status = ClientSession.RESP_FATAL;
190 session = getConnPool().getSession(UncUPLLEnums.UPLL_IPC_CHANNEL_NAME,UncUPLLEnums.UPLL_IPC_SERVICE_NAME,UncUPLLEnums.ServiceID.UPLL_EDIT_SVC_ID.ordinal(),getExceptionHandler());
191 LOG.debug("Session created successfully");
192 requestProcessor = new IpcRequestProcessor(session, getSessionID(), getConfigID(),getExceptionHandler());
193 requestProcessor.createIpcRequestPacket(IpcRequestPacketEnum.KT_VTEP_IF_UPDATE, requestBody,getUriParameters());
194 LOG.debug("Request Packet created successfully");
195 status = requestProcessor.processIpcRequest();
196 }catch (final VtnServiceException e) {
197 getExceptionHandler().raise(
198 Thread.currentThread().getStackTrace()[1].getClassName()
199 + VtnServiceConsts.HYPHEN
200 + Thread.currentThread().getStackTrace()[1].getMethodName(),
201 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
202 UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(), e);
205 if (status == ClientSession.RESP_FATAL) {
206 if(null != requestProcessor.getErrorJson()){
207 setInfo(requestProcessor.getErrorJson());
209 createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
211 status = UncResultCode.UNC_SERVER_ERROR.getValue();
213 getConnPool().destroySession(session);
215 LOG.trace("Complete VTepInterfacePortMapResource#put()");
219 * Add URI parameters to list
222 private List<String> getUriParameters() {
223 final List<String> uriParameters = new ArrayList<String>();
224 uriParameters.add(vtnName);
225 uriParameters.add(vtepName);
226 uriParameters.add(ifName);
227 return uriParameters;