示例#1
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);
    }
  }
示例#2
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);
    }
  }
示例#3
0
  @Override
  public List<RequestedHost> getRequests() {
    List<RequestedHost> requests = Lists.newArrayList();

    requests.addAll(requestDataService.getAll());

    return requests;
  }
示例#4
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);
    }
  }
示例#5
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);
    }
  }
示例#6
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
    }
  }
示例#7
0
 @Override
 public RequestedHost getRequest(final String requestId) {
   return requestDataService.find(requestId);
 }