/**
   * Implementation of get method of DomainLogicalPorts API
   *
   * @param requestBody the request Json object
   * @return Error code
   * @throws VtnServiceException
   */
  @Override
  public final int get(final JsonObject queryString) throws VtnServiceException {
    LOG.trace("Starts DomainLogicalPortsResource#get()");
    ClientSession session = null;
    IpcRequestProcessor requestProcessor = null;
    JsonObject memberLastIndex = null;
    int status = ClientSession.RESP_FATAL;
    IpcDataUnit[] resp = null;
    try {
      LOG.debug("Start Ipc framework call");
      // Get session from connection pool of UPLL server connections
      session =
          getConnPool()
              .getSession(
                  UncUPPLEnums.UPPL_IPC_CHN_NAME,
                  UncUPPLEnums.UPPL_IPC_SVC_NAME,
                  UncUPPLEnums.ServiceID.UPPL_SVC_READREQ.ordinal(),
                  getExceptionHandler());
      LOG.debug("Session created successfully");
      final IpcPhysicalResponseFactory responseGenerator = new IpcPhysicalResponseFactory();
      String dataType = VtnServiceJsonConsts.STATE;
      if (queryString.has(VtnServiceJsonConsts.TARGETDB)) {
        dataType = queryString.get(VtnServiceJsonConsts.TARGETDB).getAsString();
      }
      requestProcessor =
          new IpcRequestProcessor(session, getSessionID(), getConfigID(), getExceptionHandler());
      requestProcessor.createIpcRequestPacket(
          IpcRequestPacketEnum.KT_LOGICAL_PORT_GET, queryString, getUriParameters(queryString));
      LOG.debug("Request packet for 1st created successfully");

      if (!queryString.has(VtnServiceJsonConsts.LOGICAL_PORT_ID)) {
        status = requestProcessor.processIpcRequest();
        LOG.debug("Request packet 1st call processed with status:" + status);
        if (status == ClientSession.RESP_FATAL) {
          throw new VtnServiceException(
              Thread.currentThread().getStackTrace()[1].getClassName()
                  + VtnServiceConsts.HYPHEN
                  + Thread.currentThread().getStackTrace()[1].getMethodName(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
        }
        resp = requestProcessor.getIpcResponsePacket();
        JsonObject root = responseGenerator.getDomainLogicalPortResponse(resp, queryString);
        if (root.get(VtnServiceJsonConsts.LOGICALPORTS).isJsonArray()) {
          JsonArray domainLogicalPortArray = null;
          domainLogicalPortArray = root.getAsJsonArray(VtnServiceJsonConsts.LOGICALPORTS);

          root =
              getResponseJsonArrayPhysical(
                  queryString,
                  requestProcessor,
                  responseGenerator,
                  domainLogicalPortArray,
                  VtnServiceJsonConsts.LOGICALPORTS,
                  VtnServiceJsonConsts.LOGICAL_PORT_ID,
                  IpcRequestPacketEnum.KT_LOGICAL_PORT_GET,
                  getUriParameters(queryString),
                  VtnServiceIpcConsts.GET_DOMAIN_LOGICAL_PORT_RESPONSE);
        }

        String opType = VtnServiceJsonConsts.NORMAL;
        if (queryString.has(VtnServiceJsonConsts.OP)) {
          opType = queryString.get(VtnServiceJsonConsts.OP).getAsString();
        }
        final JsonArray logicalPortsArray = new JsonArray();
        JsonArray memberArray = null;
        JsonArray memberArrayNew = null;
        if (VtnServiceJsonConsts.STATE.equalsIgnoreCase(dataType)
            && VtnServiceJsonConsts.DETAIL.equalsIgnoreCase(opType)) {
          final Iterator<JsonElement> logicalPortIterator =
              root.get(VtnServiceJsonConsts.LOGICALPORTS).getAsJsonArray().iterator();
          requestProcessor.setServiceInfo(
              UncUPPLEnums.UPPL_IPC_SVC_NAME, UncUPPLEnums.ServiceID.UPPL_SVC_READREQ.ordinal());
          while (logicalPortIterator.hasNext()) {
            final JsonObject logicalPortsJson = (JsonObject) logicalPortIterator.next();
            requestProcessor.createIpcRequestPacket(
                IpcRequestPacketEnum.KT_LOGICAL_PORT_MEMBER_GET,
                queryString,
                getUriParametersMember(logicalPortsJson));
            requestProcessor
                .getRequestPacket()
                .setOperation(
                    IpcDataUnitWrapper.setIpcUint32Value(
                        UncOperationEnum.UNC_OP_READ_SIBLING_BEGIN.ordinal()));
            LOG.debug("Request packet for 2nd call created successfully");
            status = requestProcessor.processIpcRequest();
            LOG.debug("Request packet 2nd call processed with status:" + status);
            if (status == ClientSession.RESP_FATAL) {
              throw new VtnServiceException(
                  Thread.currentThread().getStackTrace()[1].getClassName()
                      + VtnServiceConsts.HYPHEN
                      + Thread.currentThread().getStackTrace()[1].getMethodName(),
                  UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
                  UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
            }
            resp = requestProcessor.getIpcResponsePacket();
            memberArray = responseGenerator.getDomainLogicalPortMemberResponse(resp);
            int memberIndex = 0;
            memberIndex = memberArray.size();
            if (memberArray.size() > 0) {
              while (memberIndex > 0) {
                memberIndex = memberArray.size();
                memberLastIndex = (JsonObject) memberArray.get(memberIndex - 1);
                requestProcessor.createIpcRequestPacket(
                    IpcRequestPacketEnum.KT_LOGICAL_PORT_MEMBER_GET,
                    queryString,
                    getUriParametersMemberGreaterThanDefault(logicalPortsJson, memberLastIndex));
                requestProcessor
                    .getRequestPacket()
                    .setOperation(
                        IpcDataUnitWrapper.setIpcUint32Value(
                            UncOperationEnum.UNC_OP_READ_SIBLING.ordinal()));
                status = requestProcessor.processIpcRequest();
                if (status == ClientSession.RESP_FATAL) {
                  throw new VtnServiceException(
                      Thread.currentThread().getStackTrace()[1].getClassName()
                          + VtnServiceConsts.HYPHEN
                          + Thread.currentThread().getStackTrace()[1].getMethodName(),
                      UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
                      UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
                }
                resp = requestProcessor.getIpcResponsePacket();
                memberArrayNew = responseGenerator.getDomainLogicalPortMemberResponse(resp);
                if (null != memberArrayNew && !memberArrayNew.isJsonNull()) {
                  memberArray.getAsJsonArray().addAll(memberArrayNew);
                } else {
                  break;
                }
                memberIndex = memberArrayNew.size();
              }
            }
            // get neighbor information
            getNeighbor(
                queryString, responseGenerator, requestProcessor, memberArray, logicalPortsJson);
            // get logical port boundary informations
            getBoundary(queryString, responseGenerator, requestProcessor, logicalPortsJson);
            logicalPortsArray.add(logicalPortsJson);
          }
          root.add(VtnServiceJsonConsts.LOGICALPORTS, logicalPortsArray);
        }
        setInfo(root);
      } else {
        requestProcessor
            .getRequestPacket()
            .setOperation(
                IpcDataUnitWrapper.setIpcUint32Value(UncOperationEnum.UNC_OP_READ.ordinal()));
        status = requestProcessor.processIpcRequest();
        LOG.debug("Request packet for 1st call processed with status:" + status);
        if (status == ClientSession.RESP_FATAL) {
          throw new VtnServiceException(
              Thread.currentThread().getStackTrace()[1].getClassName()
                  + VtnServiceConsts.HYPHEN
                  + Thread.currentThread().getStackTrace()[1].getMethodName(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
        }
        final JsonObject root =
            responseGenerator.getDomainLogicalPortResponse(
                requestProcessor.getIpcResponsePacket(), queryString);
        JsonArray memberArray = null;
        JsonArray memberArrayNew = null;
        String opType = VtnServiceJsonConsts.NORMAL;
        if (queryString.has(VtnServiceJsonConsts.OP)) {
          opType = queryString.get(VtnServiceJsonConsts.OP).getAsString();
        }
        if (VtnServiceJsonConsts.STATE.equalsIgnoreCase(dataType)
            && opType.equalsIgnoreCase(VtnServiceJsonConsts.DETAIL)
            && (root.get(VtnServiceJsonConsts.LOGICALPORTS).getAsJsonArray().size() != 0)) {
          requestProcessor.setServiceInfo(
              UncUPPLEnums.UPPL_IPC_SVC_NAME, UncUPPLEnums.ServiceID.UPPL_SVC_READREQ.ordinal());
          requestProcessor.createIpcRequestPacket(
              IpcRequestPacketEnum.KT_LOGICAL_PORT_MEMBER_GET,
              queryString,
              getUriParametersMemberShow(queryString));
          requestProcessor
              .getRequestPacket()
              .setOperation(
                  IpcDataUnitWrapper.setIpcUint32Value(
                      UncOperationEnum.UNC_OP_READ_SIBLING_BEGIN.ordinal()));
          LOG.debug("Request packet  2nd call created successfully");
          status = requestProcessor.processIpcRequest();
          LOG.debug("Request packet 2nd call processed with status:" + status);
          if (status == ClientSession.RESP_FATAL) {
            throw new VtnServiceException(
                Thread.currentThread().getStackTrace()[1].getClassName()
                    + VtnServiceConsts.HYPHEN
                    + Thread.currentThread().getStackTrace()[1].getMethodName(),
                UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
                UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
          }
          memberArray =
              responseGenerator.getDomainLogicalPortMemberResponse(
                  requestProcessor.getIpcResponsePacket());
          int memberIndex = 0;
          memberIndex = memberArray.size();
          JsonObject logicalPort =
              (JsonObject) root.getAsJsonArray(VtnServiceJsonConsts.LOGICALPORTS).get(0);
          if (memberArray.size() > 0) {
            while (memberIndex > 0) {
              memberIndex = memberArray.size();
              memberLastIndex = (JsonObject) memberArray.get(memberIndex - 1);
              requestProcessor.createIpcRequestPacket(
                  IpcRequestPacketEnum.KT_LOGICAL_PORT_MEMBER_GET,
                  queryString,
                  getUriParametersMemberGreaterThanDefault(logicalPort, memberLastIndex));
              requestProcessor
                  .getRequestPacket()
                  .setOperation(
                      IpcDataUnitWrapper.setIpcUint32Value(
                          UncOperationEnum.UNC_OP_READ_SIBLING.ordinal()));
              status = requestProcessor.processIpcRequest();
              if (status == ClientSession.RESP_FATAL) {
                throw new VtnServiceException(
                    Thread.currentThread().getStackTrace()[1].getClassName()
                        + VtnServiceConsts.HYPHEN
                        + Thread.currentThread().getStackTrace()[1].getMethodName(),
                    UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
                    UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage());
              }
              resp = requestProcessor.getIpcResponsePacket();
              memberArrayNew = responseGenerator.getDomainLogicalPortMemberResponse(resp);
              if (null != memberArrayNew && !memberArrayNew.isJsonNull()) {
                memberArray.getAsJsonArray().addAll(memberArrayNew);
              } else {
                break;
              }
              memberIndex = memberArrayNew.size();
            }
          }
          if (null != memberArray) {
            // get neighbor information
            getNeighbor(queryString, responseGenerator, requestProcessor, memberArray, logicalPort);
          }
          // get logical port boundary informations
          getBoundary(queryString, responseGenerator, requestProcessor, logicalPort);
          final JsonArray resultJsonArray = new JsonArray();
          resultJsonArray.add(logicalPort);
          root.add(VtnServiceJsonConsts.LOGICALPORTS, resultJsonArray);
        }
        setInfo(root);
      }
      LOG.debug("Response object created successfully");
      LOG.debug("Complete Ipc framework call");
    } catch (final VtnServiceException e) {
      getExceptionHandler()
          .raise(
              Thread.currentThread().getStackTrace()[1].getClassName()
                  + VtnServiceConsts.HYPHEN
                  + Thread.currentThread().getStackTrace()[1].getMethodName(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
              UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(),
              e);
      throw e;
    } finally {
      /*
       * Handle the case, where error info required to be set for failures
       * If error cause can be found from UPLL layer then, set the error
       * according to error code Otherwise set the error as IPC server
       * error
       */
      if (status == ClientSession.RESP_FATAL) {
        if (null != requestProcessor.getErrorJson()) {
          setInfo(requestProcessor.getErrorJson());
        } else {
          createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
        }
        status = UncResultCode.UNC_SERVER_ERROR.getValue();
      }
      // destroy the session in all cases
      getConnPool().destroySession(session);
    }
    LOG.trace("Completed LogicalPortsResource#get()");
    return status;
  }
Exemple #2
0
 /**
  * Implementation of get method of Link API.
  *
  * @param requestBody the request Json object
  * @return Error code
  * @throws VtnServiceException , in case of error .
  */
 @Override
 public final int get(final JsonObject requestBody) throws VtnServiceException {
   LOG.trace("Starts LinksResource#get()");
   ClientSession session = null;
   IpcRequestProcessor requestProcessor = null;
   int status = ClientSession.RESP_FATAL;
   try {
     LOG.debug("Start Ipc framework call");
     session =
         getConnPool()
             .getSession(
                 UncUPPLEnums.UPPL_IPC_CHN_NAME,
                 UncUPPLEnums.UPPL_IPC_SVC_NAME,
                 UncUPPLEnums.ServiceID.UPPL_SVC_READREQ.ordinal(),
                 getExceptionHandler());
     LOG.debug("Session created successfully");
     requestProcessor =
         new IpcRequestProcessor(session, getSessionID(), getConfigID(), getExceptionHandler());
     final List<String> uriParameterList = getUriParameters(requestBody);
     requestProcessor.createIpcRequestPacket(
         IpcRequestPacketEnum.KT_LINK_GET, requestBody, uriParameterList);
     if (!requestBody.has(VtnServiceJsonConsts.LINKNAME)) {
       getModifiedRequestPacket(requestBody, requestProcessor);
       LOG.debug("Request packet created successfully");
       status = requestProcessor.processIpcRequest();
       LOG.debug("Request packet processed with status:" + status);
       final IpcPhysicalResponseFactory responseGenerator = new IpcPhysicalResponseFactory();
       JsonObject responseJson =
           responseGenerator.getLinkResponse(requestProcessor.getIpcResponsePacket(), requestBody);
       if (responseJson.get(VtnServiceJsonConsts.LINKS).isJsonArray()) {
         final JsonArray responseArray =
             responseJson.get(VtnServiceJsonConsts.LINKS).getAsJsonArray();
         responseJson =
             getResponseJsonArrayPhysical(
                 requestBody,
                 requestProcessor,
                 responseGenerator,
                 responseArray,
                 VtnServiceJsonConsts.LINKS,
                 VtnServiceJsonConsts.LINKNAME,
                 IpcRequestPacketEnum.KT_LINK_GET,
                 uriParameterList,
                 VtnServiceIpcConsts.GET_LINK_RESPONSE);
       }
       setInfo(responseJson);
     } else {
       requestProcessor
           .getRequestPacket()
           .setOperation(
               IpcDataUnitWrapper.setIpcUint32Value(UncOperationEnum.UNC_OP_READ.ordinal()));
       status = requestProcessor.processIpcRequest();
       LOG.debug("Request packet processed with status:" + status);
       final IpcPhysicalResponseFactory responseGenerator = new IpcPhysicalResponseFactory();
       setInfo(
           responseGenerator.getLinkResponse(
               requestProcessor.getIpcResponsePacket(), requestBody));
     }
     LOG.debug("Response object created successfully");
     LOG.debug("Complete Ipc framework call");
   } catch (final VtnServiceException e) {
     getExceptionHandler()
         .raise(
             Thread.currentThread().getStackTrace()[1].getClassName()
                 + VtnServiceConsts.HYPHEN
                 + Thread.currentThread().getStackTrace()[1].getMethodName(),
             UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
             UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(),
             e);
     throw e;
   } finally {
     if (status == ClientSession.RESP_FATAL) {
       if (null != requestProcessor.getErrorJson()) {
         setInfo(requestProcessor.getErrorJson());
       } else {
         createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
       }
       status = UncResultCode.UNC_SERVER_ERROR.getValue();
     }
     getConnPool().destroySession(session);
   }
   LOG.trace("Completed LinksResource#get()");
   return status;
 }
 /**
  * Implementation of get method of Boundary API
  *
  * @param requestBody the request Json object
  * @return Error code
  * @throws VtnServiceException
  */
 @Override
 public final int get(final JsonObject requestBody) throws VtnServiceException {
   LOG.trace("Starts BoundariesResource#get()");
   ClientSession session = null;
   IpcRequestProcessor requestProcessor = null;
   int status = ClientSession.RESP_FATAL;
   try {
     LOG.debug("Start Ipc framework call");
     session =
         getConnPool()
             .getSession(
                 UncUPPLEnums.UPPL_IPC_CHN_NAME,
                 UncUPPLEnums.UPPL_IPC_SVC_NAME,
                 UncUPPLEnums.ServiceID.UPPL_SVC_READREQ.ordinal(),
                 getExceptionHandler());
     LOG.debug("Session created successfully");
     requestProcessor =
         new IpcRequestProcessor(session, getSessionID(), getConfigID(), getExceptionHandler());
     /*
      * operation type will be required to resolve the response type
      */
     String opType = VtnServiceJsonConsts.NORMAL;
     if (requestBody.has(VtnServiceJsonConsts.OP)) {
       opType = requestBody.get(VtnServiceJsonConsts.OP).getAsString();
     }
     final List<String> uriParameterList = getUriParameters(requestBody);
     requestProcessor.createIpcRequestPacket(
         IpcRequestPacketEnum.KT_BOUNDARY_GET, requestBody, getUriParameters(requestBody));
     if (opType.equalsIgnoreCase(VtnServiceJsonConsts.COUNT)) {
       requestProcessor.createIpcRequestPacket(
           IpcRequestPacketEnum.KT_BOUNDARY_GET_COUNT, requestBody, getUriParameters(requestBody));
     }
     LOG.debug("Request packet created successfully");
     status = requestProcessor.processIpcRequest();
     LOG.debug("Request packet processed with status:" + status);
     final IpcPhysicalResponseFactory responseGenerator = new IpcPhysicalResponseFactory();
     /*
      * setInfo(responseGenerator.getBoundaryResponse(
      * requestProcessor.getIpcResponsePacket(), requestBody,
      * VtnServiceJsonConsts.LIST));
      */
     JsonObject responseJson =
         responseGenerator.getBoundaryResponse(
             requestProcessor.getIpcResponsePacket(), requestBody, VtnServiceJsonConsts.LIST);
     if (responseJson.get(VtnServiceJsonConsts.BOUNDARIES).isJsonArray()) {
       final JsonArray responseArray =
           responseJson.get(VtnServiceJsonConsts.BOUNDARIES).getAsJsonArray();
       responseJson =
           getResponseJsonArrayPhysical(
               requestBody,
               requestProcessor,
               responseGenerator,
               responseArray,
               VtnServiceJsonConsts.BOUNDARIES,
               VtnServiceJsonConsts.BOUNDARYID,
               IpcRequestPacketEnum.KT_BOUNDARY_GET,
               uriParameterList,
               VtnServiceIpcConsts.GET_BOUNDARY_RESPONSE);
     }
     setInfo(responseJson);
     LOG.debug("Response object created successfully");
     LOG.debug("Complete Ipc framework call");
   } catch (final VtnServiceException e) {
     getExceptionHandler()
         .raise(
             Thread.currentThread().getStackTrace()[1].getClassName()
                 + VtnServiceConsts.HYPHEN
                 + Thread.currentThread().getStackTrace()[1].getMethodName(),
             UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorCode(),
             UncJavaAPIErrorCode.IPC_SERVER_ERROR.getErrorMessage(),
             e);
     throw e;
   } finally {
     if (status == ClientSession.RESP_FATAL) {
       if (null != requestProcessor.getErrorJson()) {
         setInfo(requestProcessor.getErrorJson());
       } else {
         createErrorInfo(UncCommonEnum.UncResultCode.UNC_SERVER_ERROR.getValue());
       }
       status = UncResultCode.UNC_SERVER_ERROR.getValue();
     }
     getConnPool().destroySession(session);
   }
   LOG.trace("Completed BoundariesResource#get()");
   return status;
 }