Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  @MethodLog
  public synchronized long registerPlatformIdent(
      List<String> definedIPs, String agentName, String version) throws BusinessException {
    if (log.isInfoEnabled()) {
      log.info("Trying to register Agent '" + agentName + "'");
    }

    // find existing registered
    List<PlatformIdent> platformIdentResults;
    if (ipBasedAgentRegistration) {
      platformIdentResults = platformIdentDao.findByNameAndIps(agentName, definedIPs);
    } else {
      platformIdentResults = platformIdentDao.findByName(agentName);
    }

    PlatformIdent platformIdent = new PlatformIdent();
    platformIdent.setAgentName(agentName);
    if (1 == platformIdentResults.size()) {
      platformIdent = platformIdentResults.get(0);
    } else if (platformIdentResults.size() > 1) {
      // this cannot occur anymore, if it occurs, then there is something totally wrong!
      log.error(
          "More than one platform ident has been retrieved! Please send your Database to the NovaTec inspectIT support!");
      throw new BusinessException(
          "Register the agent with name "
              + agentName
              + " and following network interfaces "
              + definedIPs
              + ".",
          AgentManagementErrorCodeEnum.MORE_THAN_ONE_AGENT_REGISTERED);
    }

    // always update the time stamp and ips, no matter if this is an old or new record.
    platformIdent.setTimeStamp(new Timestamp(GregorianCalendar.getInstance().getTimeInMillis()));
    platformIdent.setDefinedIPs(definedIPs);

    // also always update the version information of the agent
    platformIdent.setVersion(version);

    platformIdentDao.saveOrUpdate(platformIdent);

    agentStatusDataProvider.registerConnected(platformIdent.getId());

    if (log.isInfoEnabled()) {
      log.info(
          "Successfully registered the Agent '"
              + agentName
              + "' with id "
              + platformIdent.getId()
              + ", version "
              + version
              + " and following network interfaces:");
      printOutDefinedIPs(definedIPs);
    }
    return platformIdent.getId();
  }