Example #1
0
  @Override
  public void run() {
    this.logger.info("Starting sender thread...");

    if (this.op.equalsIgnoreCase("createReservation")) {
      Element response;
      try {

        // this.logger.info("SENDER: sending CreateReservation
        // request");

        final CreateReservation create = new CreateReservation();
        create.setCreateReservation((CreateReservationType) this.msg);

        response =
            this.proxyRSV.createReservation(JaxbSerializer.getInstance().objectToElement(create));

        final CreateReservationResponse res =
            (CreateReservationResponse) JaxbSerializer.getInstance().elementToObject(response);

        // logger.info("SENDER: received CreateReservation response");

        this.result = res.getCreateReservationResponse();

      } catch (final SoapFault e) {
        this.rollback = true;
        this.exception = e;
        e.printStackTrace();
      }
    } else if (this.op.equalsIgnoreCase("activateReservation")) {
      Element response;
      try {
        final Activate act = new Activate();
        act.setActivate((ActivateType) this.msg);

        response = this.proxyRSV.activate(JaxbSerializer.getInstance().objectToElement(act));

        final ActivateResponse res =
            (ActivateResponse) JaxbSerializer.getInstance().elementToObject(response);

        this.result = res.getActivateResponse();

      } catch (final SoapFault e) {
        this.exception = e;
        e.printStackTrace();
      }
    } else if (this.op.equalsIgnoreCase("cancelReservation")) {
      Element response;
      try {

        final CancelReservation cancel = new CancelReservation();

        cancel.setCancelReservation((CancelReservationType) this.msg);

        response =
            this.proxyRSV.cancelReservation(JaxbSerializer.getInstance().objectToElement(cancel));

        final CancelReservationResponse res =
            (CancelReservationResponse) JaxbSerializer.getInstance().elementToObject(response);

        this.result = res.getCancelReservationResponse();

      } catch (final SoapFault e) {
        this.exception = e;
        e.printStackTrace();
      }
    } else if (this.op.equalsIgnoreCase("getStatus")) {
      Element response;
      try {
        final GetStatus get = new GetStatus();
        get.setGetStatus((GetStatusType) this.msg);

        response = this.proxyRSV.getStatus(JaxbSerializer.getInstance().objectToElement(get));

        final GetStatusResponse res =
            (GetStatusResponse) JaxbSerializer.getInstance().elementToObject(response);

        this.result = res.getGetStatusResponse();

      } catch (final SoapFault e) {
        this.exception = e;
        e.printStackTrace();
      }
    } else if (this.op.equalsIgnoreCase("isAvailable")) {
      Element response;
      try {

        final IsAvailable avail = new IsAvailable();
        avail.setIsAvailable((IsAvailableType) this.msg);

        response = this.proxyRSV.isAvailable(JaxbSerializer.getInstance().objectToElement(avail));

        // logger.info("Request Sender: received IsAvailable response");

        final IsAvailableResponse res =
            (IsAvailableResponse) JaxbSerializer.getInstance().elementToObject(response);

        this.result = res.getIsAvailableResponse();

      } catch (final SoapFault e) {
        this.exception = e;
        e.printStackTrace();
      }
    } else if (this.op.equalsIgnoreCase("getReservations")) {
      Element response;
      try {

        final GetReservations getRsvs = new GetReservations();
        getRsvs.setGetReservations((GetReservationsType) this.msg);

        response =
            this.proxyRSV.getReservations(JaxbSerializer.getInstance().objectToElement(getRsvs));

        final GetReservationsResponse res =
            (GetReservationsResponse) JaxbSerializer.getInstance().elementToObject(response);

        this.result = res.getGetReservationsResponse();

      } catch (final SoapFault e) {
        this.exception = e;
        e.printStackTrace();
      }
    }

    this.logger.info("finished");
    this.performanceLogger.log(
        PerformanceLogLevel.PERFORMANCE_LOG,
        "NRPS_response_time "
            + this.domain.getName()
            + " "
            + this.proxyRSV.getLastCallDuration()
            + "ms");
  }
Example #2
0
  /**
   * Creates a new reservation in the thin Nrps.
   *
   * @param createReservationRequest request
   * @return response for request as CreateReservationResponseType
   * @throws UnexpectedFaultException if reservation is not of type fixed
   * @throws InvalidReservationIDFaultException
   */
  public CreateReservationResponseType createReservation(
      final CreateReservationType createReservationRequest)
      throws UnexpectedFaultException, InvalidReservationIDFaultException {

    CreateReservationResponseType response = new CreateReservationResponseType();

    long jobId = System.currentTimeMillis();
    if (createReservationRequest.isSetJobID()
        && createReservationRequest.getJobID().longValue() > 0) {
      jobId = createReservationRequest.getJobID().longValue();
    }

    long reservationId =
        DbManager.insertReservation(jobId, createReservationRequest.getNotificationConsumerURL());

    boolean success = true;
    boolean partSuccess = false;

    List<GmplsConnection> connections = new ArrayList<GmplsConnection>();

    response.setJobID(Long.valueOf(jobId));
    response.setReservationID(WebserviceUtils.convertReservationID(reservationId));

    for (ServiceConstraintType sct : createReservationRequest.getService()) {
      if (sct.getTypeOfReservation()
          .equals(
              org.opennaas.extensions.idb.serviceinterface.databinding.jaxb.ReservationType
                  .FIXED)) {

        Calendar calStart =
            Helpers.xmlCalendarToCalendar(sct.getFixedReservationConstraints().getStartTime());
        Timestamp startTime = new Timestamp(calStart.getTime().getTime());

        calStart.setTimeZone(SimpleTimeZone.getDefault());
        calStart.add(Calendar.SECOND, sct.getFixedReservationConstraints().getDuration());
        Timestamp endTime = new Timestamp(calStart.getTimeInMillis());
        for (ConnectionConstraintType cct : sct.getConnections()) {
          GmplsConnection con = new GmplsConnection();
          con.setJobId(jobId);
          con.setReservationId(reservationId);
          con.setServiceId(sct.getServiceID());
          con.setConnectionId(cct.getConnectionID());
          con.setSrcTNA(cct.getSource().getEndpointId());
          con.setDestTNA(cct.getTarget().get(0).getEndpointId());
          con.setStartTime(startTime);
          con.setEndTime(endTime);
          con.setBandwidth(cct.getMinBW());
          con.setAutoActivation(sct.isAutomaticActivation());

          try {
            partSuccess = DbManager.insertConnection(con);
          } catch (SourcePortUnavailableException e) {
            partSuccess = false;
            logger.error(e.getMessage(), e);
          } catch (DestinationPortUnavailableException e) {
            partSuccess = false;
            logger.error(e.getMessage(), e);
          } catch (SourceAndDestinationPortUnavailableException e) {
            partSuccess = false;
            logger.error(e.getMessage(), e);
          } catch (PathNotFoundException e) {
            partSuccess = false;
            logger.error(e.getMessage(), e);
          }

          if (partSuccess) {
            connections.add(con);
          }

          success &= partSuccess;
        }
      } else {
        DbManager.deleteWholeReservation(reservationId);
        throw new UnexpectedFaultException("Only FIXED ReservationType supported");
      }
    }

    if (!success) {
      logger.debug("No success");
      DbManager.deleteWholeReservation(reservationId);
      throw new UnexpectedFaultException("No Path found.");
    }
    for (GmplsConnection gmplsConnection : connections) {
      try {
        if (gmplsConnection.isAutoActivation()) {

          if (gmplsConnection
                  .getStartTime()
                  .before(Helpers.xmlCalendarToDate(Helpers.generateXMLCalendar(0, 0)))
              && gmplsConnection
                  .getEndTime()
                  .after(Helpers.xmlCalendarToDate(Helpers.generateXMLCalendar()))) {
            if (0 <= setUpConnection(gmplsConnection)) {
              JobManager.getInstance().schedulePathTermination(gmplsConnection);

            } else {
              gmplsConnection.setStatus(StatusType.UNKNOWN);
              DbManager.updateStatus(
                  gmplsConnection, "Path could not be set up! PathId returned is 0");
              throw new UnexpectedFaultException("Path could not be set up");
            }
          } else {
            JobManager.getInstance().schedulePathSetUp(gmplsConnection);
            JobManager.getInstance().schedulePathTermination(gmplsConnection);
            gmplsConnection.setStatus(StatusType.PENDING);
            DbManager.updateStatus(gmplsConnection, "Connection has been scheduled");
          }
        }
      } catch (SchedulerException e) {
        gmplsConnection.setStatus(StatusType.UNKNOWN);
        DbManager.updateStatus(gmplsConnection, e.getMessage());
        throw new UnexpectedFaultException(e);
      } catch (InvalidRequestFaultException e) {
        gmplsConnection.setStatus(StatusType.UNKNOWN);
        DbManager.updateStatus(gmplsConnection, e.getMessage());
        throw new UnexpectedFaultException(e);
      } catch (SoapFault e) {
        gmplsConnection.setStatus(StatusType.UNKNOWN);
        DbManager.updateStatus(gmplsConnection, e.getMessage());
        throw new UnexpectedFaultException(e);
      }
    }
    Notifications.addTopic(response.getReservationID());
    return response;
  }