Exemplo n.º 1
0
  /**
   * Update all known Provisioners of the new ResourceCapability
   *
   * @param resourceCapability The ResourceCapability object
   * @param deployedServices List of deployed services
   */
  void updateMonitors(
      ResourceCapability resourceCapability, List<DeployedService> deployedServices) {
    ProvisionLeaseManager[] mgrs;
    synchronized (leaseTable) {
      Collection<ProvisionLeaseManager> c = leaseTable.values();
      mgrs = c.toArray(new ProvisionLeaseManager[c.size()]);
    }
    if (mgrs == null) return;
    if (mgrs.length == 0) return;

    for (ProvisionLeaseManager mgr : mgrs) {
      try {
        mgr.provisioner.update(
            adapter.getInstantiator(), resourceCapability, deployedServices, serviceLimit);
      } catch (Throwable t) {
        if (logger.isLoggable(Level.FINEST))
          logger.log(Level.FINEST, "Updating ProvisionManager", t);
        boolean connected = false;

        /* Determine if we should even try to reconnect */
        final int category = ThrowableConstants.retryable(t);
        if (category == ThrowableConstants.INDEFINITE
            || category == ThrowableConstants.UNCATEGORIZED) {
          connected = mgr.reconnect();
        }

        if (!connected) {
          removeProvisionManager(mgr.provisioner, mgr.serviceID);
        }
      }
    }
  }
Exemplo n.º 2
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);
  }