Esempio n. 1
0
  @Override
  public void rejectRequest(final String requestId) throws HostRegistrationException {
    try {
      RequestedHostImpl registrationRequest = requestDataService.find(requestId);
      registrationRequest.setStatus(ResourceHostRegistrationStatus.REJECTED);
      requestDataService.update(registrationRequest);
    } catch (Exception e) {
      LOG.error("Error rejecting agent registration request", e);

      throw new HostRegistrationException(e);
    }
  }
Esempio n. 2
0
  @Override
  public void approveRequest(final String requestId) throws HostRegistrationException {
    try {
      RequestedHostImpl registrationRequest = requestDataService.find(requestId);

      if (registrationRequest == null
          || !ResourceHostRegistrationStatus.REQUESTED.equals(registrationRequest.getStatus())) {
        return;
      }

      registrationRequest.setStatus(ResourceHostRegistrationStatus.APPROVED);

      requestDataService.update(registrationRequest);

      importHostPublicKey(registrationRequest.getId(), registrationRequest.getPublicKey(), true);

      importHostSslCert(registrationRequest.getId(), registrationRequest.getCert());

      for (final ContainerInfo containerInfo : registrationRequest.getHostInfos()) {
        importHostPublicKey(containerInfo.getId(), containerInfo.getPublicKey(), false);
      }
    } catch (Exception e) {
      LOG.error("Error approving agent registration request", e);

      throw new HostRegistrationException(e);
    }
  }
Esempio n. 3
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
    }
  }
Esempio n. 4
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);
    }
  }