예제 #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();
  }
예제 #2
0
  /**
   * {@inheritDoc}
   *
   * @throws BusinessException
   */
  @Override
  @MethodLog
  public void unregisterPlatformIdent(List<String> definedIPs, String agentName)
      throws BusinessException {
    log.info("Trying to unregister the Agent with following network interfaces:");
    printOutDefinedIPs(definedIPs);

    List<PlatformIdent> platformIdentResults =
        platformIdentDao.findByNameAndIps(agentName, definedIPs);

    if (1 == platformIdentResults.size()) {
      PlatformIdent platformIdent = platformIdentResults.get(0);
      agentStatusDataProvider.registerDisconnected(platformIdent.getId());
      log.info(
          "The Agent '" + platformIdent.getAgentName() + "' has been successfully unregistered.");
    } 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(
          "Unregister the agent with name "
              + agentName
              + " and following network interfaces "
              + definedIPs
              + ".",
          AgentManagementErrorCodeEnum.MORE_THAN_ONE_AGENT_REGISTERED);
    } else {
      log.warn(
          "No registered agent with given network interfaces exists. Unregistration is aborted.");
      throw new BusinessException(
          "Unregister the agent with name "
              + agentName
              + " and following network interfaces "
              + definedIPs
              + ".",
          AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST);
    }
  }