示例#1
0
  @Override
  public void removeRequest(final String requestId) throws HostRegistrationException {
    try {
      RequestedHost requestedHost = requestDataService.find(requestId);

      if (requestedHost != null) {
        requestDataService.remove(requestedHost.getId());

        LocalPeer localPeer = serviceLocator.getService(LocalPeer.class);

        localPeer.removeResourceHost(requestedHost.getId());
      }
    } catch (HostNotFoundException e) {
      LOG.warn("Error removing agent registration request: {}", e.getMessage());
    } catch (Exception e) {
      LOG.error("Error removing agent registration request", e);

      throw new HostRegistrationException(e);
    }
  }
示例#2
0
  protected void checkManagement(RequestedHost requestedHost) {
    try {
      if (requestedHost.getStatus() == ResourceHostRegistrationStatus.REQUESTED
          && containsManagementContainer(requestedHost.getHostInfos())) {
        boolean managementAlreadyApproved = false;

        for (RequestedHostImpl requestedHostImpl : requestDataService.getAll()) {
          if (requestedHostImpl.getStatus() == ResourceHostRegistrationStatus.APPROVED
              && containsManagementContainer(requestedHostImpl.getHostInfos())) {
            managementAlreadyApproved = true;
            break;
          }
        }

        if (!managementAlreadyApproved) {
          approveRequest(requestedHost.getId());
        }
      }
    } catch (Exception e) {
      // ignore
    }
  }
示例#3
0
  @RolesAllowed("Resource-Management|Write")
  @Override
  public synchronized void queueRequest(final RequestedHost requestedHost)
      throws HostRegistrationException {
    Preconditions.checkNotNull(requestedHost, "'Invalid registration request");
    Preconditions.checkArgument(
        PGPKeyUtil.isValidPublicKeyring(requestedHost.getPublicKey()), "Invalid public key");

    try {
      RequestedHostImpl requestedHostImpl = requestDataService.find(requestedHost.getId());

      if (requestedHostImpl != null) {
        LOG.info("Already requested registration");

        // update hostname

        if (!Strings.isNullOrEmpty(requestedHost.getHostname())
            && !requestedHostImpl.getHostname().equalsIgnoreCase(requestedHost.getHostname())) {
          requestedHostImpl.setHostname(requestedHost.getHostname());

          requestDataService.update(requestedHostImpl);
        }
      } else {
        RequestedHostImpl registrationRequest = new RequestedHostImpl(requestedHost);

        registrationRequest.setStatus(ResourceHostRegistrationStatus.REQUESTED);

        requestDataService.update(registrationRequest);

        checkManagement(registrationRequest);
      }
    } catch (Exception e) {
      LOG.error("Error queueing agent registration request", e);

      throw new HostRegistrationException(e);
    }
  }