/** {@inheritDoc} */
  @Override
  public void onApplicationEvent(AgentMappingsUpdateEvent event) {
    Map<Long, AgentCacheEntry> agentCacheMap = nextGenInstrumentationManager.getAgentCacheMap();
    // iterate all caches
    for (AgentCacheEntry agentCacheEntry : agentCacheMap.values()) {
      ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
      Environment cachedEnvironment = configurationHolder.getEnvironment();
      PlatformIdent platformIdent = platformIdentDao.load(agentCacheEntry.getId());
      try {
        // see what 's the new environment for the agent
        Environment environment =
            configurationResolver.getEnvironmentForAgent(
                platformIdent.getDefinedIPs(), platformIdent.getAgentName());

        // fire job only if we have new environment or we were not bounded to any
        // environment
        if ((null == cachedEnvironment)
            || !ObjectUtils.equals(cachedEnvironment.getId(), environment.getId())) {
          EnvironmentMappingUpdateJob mappingUpdateJob = mappingUpdateJobFactory.getObject();
          mappingUpdateJob.setEnvironment(environment);
          mappingUpdateJob.setAgentCacheEntry(agentCacheEntry);

          executor.execute(mappingUpdateJob);
        }
      } catch (BusinessException e) {
        // if we have exception by resolving new environment run job with no new
        // environment
        EnvironmentMappingUpdateJob mappingUpdateJob = mappingUpdateJobFactory.getObject();
        mappingUpdateJob.setAgentCacheEntry(agentCacheEntry);

        executor.execute(mappingUpdateJob);
      }
    }
  }
Ejemplo n.º 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);
    }
  }