@Override
    public void run() {
      try {
        ReservationStatus currentStatus = null;

        // No need to retrieve status when there is no reservationId
        while (numberOfTries < maxPollingTries && reservation.getReservationId() != null) {

          // Get the latest version of the reservation..
          Reservation reservationFresh = reservationService.find(reservation.getId());

          logger.debug(
              "Checking status update for: '{}' (try {})",
              reservation.getReservationId(),
              numberOfTries);

          currentStatus = reservationService.getStatus(reservationFresh);
          logger.debug("Got back status {}", currentStatus);

          if (!currentStatus.equals(startStatus)) {
            logger.info(
                "Status change detected {} -> {} for reservation {}",
                new Object[] {startStatus, currentStatus, reservationFresh.getReservationId()});

            reservationFresh = reservationService.updateStatus(reservationFresh, currentStatus);

            Optional<NsiRequestDetails> requestDetails;
            if (reservationFresh.getConnection().isPresent()) {
              requestDetails =
                  Optional.fromNullable(
                      reservationFresh.getConnection().get().getProvisionRequestDetails());
            } else {
              requestDetails = Optional.absent();
            }

            reservationEventPublisher.notifyListeners(
                new ReservationStatusChangeEvent(startStatus, reservationFresh, requestDetails));

            return;
          }

          numberOfTries++;
          Uninterruptibles.sleepUninterruptibly(pollingIntervalInMillis, TimeUnit.MILLISECONDS);
        }
      } catch (Exception e) {
        logger.error(
            "The poller failed for reservation "
                + reservation.getId()
                + "/"
                + reservation.getReservationId(),
            e);
        emailSender.sendErrorMail(e);
      }
    }
  @Test
  @Ignore
  public void shouldCreateReservation() {
    PhysicalPort sourcePort = createPort("SAP-00:03:18:58:ce:20-8", "00:03:18:58:ce:20", "1-1-1-8");
    PhysicalPort destPort = createPort("SAP-00:03:18:58:ce:20-4", "00:03:18:58:ce:20", "1-1-1-8");

    Reservation reservation =
        new ReservationFactory()
            .setReservationId("SURFnetTest3")
            .setStartDateTime(DateTime.now().plusMinutes(2))
            .setEndDateTime(DateTime.now().plusMinutes(20))
            .setName("mtosiSurfTest5")
            .create();

    reservation.getSourcePort().setPhysicalPort(sourcePort);
    reservation.getDestinationPort().setPhysicalPort(destPort);

    Reservation savedReservation = subject.reserve(reservation, false);

    System.err.println(savedReservation);
  }
 public ReservationStatusChecker(Reservation reservation, int maxPollingTries) {
   this.reservation = reservation;
   this.maxPollingTries = maxPollingTries;
   this.startStatus = reservation.getStatus();
 }
  public ReservationView(
      Reservation reservation,
      ElementActionView deleteActionView,
      ElementActionView modifyActionView,
      ElementActionView copyActionView) {
    this.id = reservation.getId();
    this.virtualResourceGroup =
        reservation.getVirtualResourceGroup().map(g -> g.getName()).orElse("-");
    this.sourcePort = new PortView(reservation.getSourcePort());
    this.destinationPort = new PortView(reservation.getDestinationPort());
    // `<c:out>` strips newlines, so we have to manually HTML escape.
    this.failedReason = HtmlUtils.htmlEscape(reservation.formattedFailedReason(), "UTF-8");
    this.cancelReason = HtmlUtils.htmlEscape(reservation.getCancelReason(), "UTF-8");
    this.startDateTime = reservation.getStartDateTime();
    this.endDateTime = reservation.getEndDateTime().orElse(null);
    this.bandwidth = reservation.getBandwidth();
    this.userCreated = reservation.getUserCreated();
    this.providerConnectionId = reservation.getProviderConnectionId();
    this.creationDateTime = reservation.getCreationDateTime();
    this.protectionType = reservation.getRequesterConnection().getProtectionType();
    this.name = reservation.getName();
    NsiRequesterConnection connection = reservation.getRequesterConnection();
    this.requesterConnectionId = connection.getConnectionId();
    this.ero = presentEro(connection);

    states = connection.getStates().toShortString();
    reservationState = connection.getReservationState();
    provisionState = connection.getProvisionState().orElse(null);
    lifecycleState = connection.getLifecycleState();
    dataPlaneActive = connection.isDataPlaneActive();

    this.deleteActionView = deleteActionView;
    this.modifyActionView = modifyActionView;
    this.copyActionView = copyActionView;
  }