Ejemplo n.º 1
0
 ProvisionLeaseManager(Lease lease, ProvisionManager provisioner, ServiceID serviceID) {
   super("ProvisionLeaseManager");
   this.lease = lease;
   leaseTime = lease.getExpiration() - System.currentTimeMillis();
   if (logger.isLoggable(Level.FINEST))
     logger.log(
         Level.FINEST,
         "ProvisionMonitor Lease expiration : "
             + "["
             + lease.getExpiration()
             + "]  millis, "
             + "["
             + (lease.getExpiration() / 1000)
             + "] seconds, "
             + "duration : ["
             + leaseTime
             + "] millis, "
             + "["
             + (leaseTime / 1000)
             + "], secs");
   this.provisioner = provisioner;
   this.serviceID = serviceID;
   setDaemon(true);
   start();
 }
Ejemplo n.º 2
0
 /**
  * Attempt to reconnect to the ProvisionMonitor
  *
  * @return True if reconnected, false if not
  */
 boolean reconnect() {
   if (!keepAlive) return (false);
   this.lease = connect(provisioner);
   boolean connected = (lease != null);
   /* If we're not connected, set keepAlive flag to false */
   if (!connected) keepAlive = false;
   else this.leaseTime = lease.getExpiration() - System.currentTimeMillis();
   return (connected);
 }
Ejemplo n.º 3
0
 void drop(boolean removed) {
   if (!removed) {
     try {
       lease.cancel();
     } catch (AccessControlException e) {
       logger.log(
           Level.WARNING, "Permissions porblen dropping lease", ThrowableUtil.getRootCause(e));
     } catch (Exception e) {
       if (logger.isLoggable(Level.FINER))
         logger.finer("ProvisionLeaseManager: could not " + "drop lease, already cancelled");
     }
   }
   lease = null;
   keepAlive = false;
   interrupt();
 }
Ejemplo n.º 4
0
    public void run() {
      long leaseRenewalTime = TimeUtil.computeLeaseRenewalTime(leaseTime);

      while (!interrupted()) {
        if (!keepAlive) {
          return;
        }
        try {
          sleep(leaseRenewalTime);
        } catch (InterruptedException ie) {
          /* should not happen */
        } catch (IllegalArgumentException iae) {
          logger.warning("Lease renewal time incorrect : " + leaseRenewalTime);
        }
        if (lease != null) {
          try {
            lease.renew(leaseTime);
          } catch (Exception e) {
            /* Determine if we should even try to reconnect */
            if (!ThrowableUtil.isRetryable(e)) {
              keepAlive = false;
              if (logger.isLoggable(Level.FINEST))
                logger.log(
                    Level.FINEST, "Unrecoverable Exception renewing" + "ProvisionManager Lease", e);
              if (logger.isLoggable(Level.FINE))
                logger.log(
                    Level.FINE, "Unrecoverable Exception renewing" + "ProvisionManager Lease");
            }
            if (keepAlive) {
              /*
               * If we failed to renew the Lease we should try and
               * re-establish comms to the ProvisionManager and get
               * another Lease
               */
              if (logger.isLoggable(Level.FINE))
                logger.log(Level.FINE, "Could not renew, attempt to " + "reconnect");
              boolean connected = reconnect();
              if (!connected) {
                logger.log(
                    Level.WARNING, "Unable to recover ProvisionManager " + "registration, exiting");
                break;
              }

            } else {
              if (logger.isLoggable(Level.FINE))
                logger.log(
                    Level.FINE, "No retry attempted, ProvisionMonitor " + "determined unreachable");
              break;
            }
          }
        }
      }

      /* Broken out of loop, make sure we are removed from the
       * leaseManagerTable */
      Object removed = leaseTable.remove(provisioner);
      if (removed != null) {
        if (logger.isLoggable(Level.FINE))
          logger.log(Level.FINE, "Remove ProvisionLeaseManager from leaseManagerTable");
      }
    }
Ejemplo n.º 5
0
  /**
   * Attempt to connect to the ProvisionMonitor
   *
   * @param provisioner The provision monitor to connect to
   * @return The Lease the ProvisionMonitor has returned, or null if a valid Lease could not be
   *     obtained
   */
  synchronized Lease connect(ProvisionManager provisioner) {
    boolean connected = false;
    Lease lease = null;
    for (int i = 1; i <= provisionerRetryCount; i++) {
      try {
        EventRegistration er =
            provisioner.register(
                adapter.getInstantiator(),
                null,
                adapter.getResourceCapability(),
                getServiceDeployments(),
                serviceLimit,
                provisionerLeaseDuration);
        lease = (Lease) provisionerPreparer.prepareProxy(er.getLease());
        long leaseTime = lease.getExpiration() - System.currentTimeMillis();
        if (leaseTime > 0) {
          if (logger.isLoggable(Level.FINE))
            logger.log(Level.FINE, "Established ProvisionManager registration");
          connected = true;
          break;
        } else {
          logger.log(
              Level.WARNING,
              "Invalid Lease time ["
                  + leaseTime
                  + "] returned from "
                  + "ProvisionManager, retry count ["
                  + i
                  + "]");
          try {
            lease.cancel();
          } catch (Exception e) {
            if (logger.isLoggable(Level.FINEST))
              logger.log(Level.FINEST, "Cancelling Lease with invalid lease time", e);
          }
          try {
            Thread.sleep(provisionerRetryDelay);
          } catch (InterruptedException ie) {
            /* should not happen */
          }
        }

      } catch (SecurityException e) {
        // cancelRegistration(provisioner);
        logger.log(Level.WARNING, "ProvisionManager security exception", e);
        break;
      } catch (Exception e) {
        Throwable cause = ThrowableUtil.getRootCause(e);
        logger.warning(
            "Recovering ProvisionManager Lease attempt "
                + "retry count ["
                + i
                + "] "
                + cause.getClass().getName()
                + ": "
                + cause.getMessage());
        /* Determine if we should even try to reconnect */
        final int category = ThrowableConstants.retryable(e);
        if (category == ThrowableConstants.INDEFINITE
            || category == ThrowableConstants.UNCATEGORIZED) {
          try {
            Thread.sleep(provisionerRetryDelay);
          } catch (InterruptedException ie) {
            /* should not happen */
          }
        }
      }
    }
    /* If we're not connected, set lease to null and return */
    if (!connected) lease = null;
    return (lease);
  }