コード例 #1
0
  @RequiresSession
  public Map<String, List<HostConfigMapping>> findSelectedHostsByTypes(
      final long clusterId, Collection<String> types) {

    populateCache();

    Map<String, List<HostConfigMapping>> mappingsByType =
        new HashMap<String, List<HostConfigMapping>>();

    for (String type : types) {
      if (!mappingsByType.containsKey(type)) {
        mappingsByType.put(type, new ArrayList<HostConfigMapping>());
      }
    }

    if (!types.isEmpty()) {
      List<HostConfigMapping> mappings = new ArrayList<HostConfigMapping>();

      for (Set<HostConfigMapping> entries : hostConfigMappingByHost.values()) {

        for (HostConfigMapping entry : entries) {

          if (types.contains(entry.getType()) && entry.getClusterId().equals(clusterId))
            mappings.add(new HostConfigMappingImpl(entry));
        }
      }

      for (HostConfigMapping mapping : mappings) {
        mappingsByType.get(mapping.getType()).add(mapping);
      }
    }

    return mappingsByType;
  }
コード例 #2
0
  @Transactional
  public void create(HostConfigMapping hostConfigMapping) {

    populateCache();

    // create in db
    entityManagerProvider.get().persist(buildHostConfigMappingEntity(hostConfigMapping));

    // create in cache
    Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostConfigMapping.getHostName());
    if (set == null) {
      set = new HashSet<HostConfigMapping>();
      hostConfigMappingByHost.put(hostConfigMapping.getHostName(), set);
    }

    set.add(hostConfigMapping);
  }
コード例 #3
0
  public HostConfigMapping buildHostConfigMapping(HostConfigMappingEntity hostConfigMappingEntity) {

    HostConfigMapping hostConfigMapping = new HostConfigMappingImpl();

    hostConfigMapping.setClusterId(hostConfigMappingEntity.getClusterId());
    hostConfigMapping.setCreateTimestamp(hostConfigMappingEntity.getCreateTimestamp());
    hostConfigMapping.setHostName(hostConfigMappingEntity.getHostName());
    hostConfigMapping.setServiceName(hostConfigMappingEntity.getServiceName());
    hostConfigMapping.setType(hostConfigMappingEntity.getType());
    hostConfigMapping.setUser(hostConfigMappingEntity.getUser());
    hostConfigMapping.setSelected(hostConfigMappingEntity.isSelected());
    hostConfigMapping.setVersion(hostConfigMappingEntity.getVersion());

    return hostConfigMapping;
  }
コード例 #4
0
  @Transactional
  public HostConfigMapping merge(HostConfigMapping hostConfigMapping) {

    populateCache();

    Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostConfigMapping.getHostName());
    if (set == null) {
      set = new HashSet<HostConfigMapping>();
      hostConfigMappingByHost.put(hostConfigMapping.getHostName(), set);
    }

    // Update object in set
    set.remove(hostConfigMapping);
    set.add(hostConfigMapping);

    entityManagerProvider.get().merge(buildHostConfigMappingEntity(hostConfigMapping));

    return hostConfigMapping;
  }