Package org.apache.ambari.server.orm.entities

Examples of org.apache.ambari.server.orm.entities.HostConfigMappingEntity


  public void teardown() throws AmbariException {
    injector.getInstance(PersistService.class).stop();
  }
 
  private HostConfigMappingEntity createEntity(long clusterId, String host, String type, String version) throws Exception {
    HostConfigMappingEntity entity = new HostConfigMappingEntity();
    entity.setClusterId(Long.valueOf(clusterId));
    entity.setCreateTimestamp(Long.valueOf(System.currentTimeMillis()));
    entity.setHostName(host);
    entity.setSelected(1);
    entity.setType(type);
    entity.setVersion(version);
    entity.setUser("_test");
   
    hostConfigMappingDAO.create(entity);
   
    return entity;
  }
View Full Code Here


  }
 

  @Test
  public void testFindByType() throws Exception {
    HostConfigMappingEntity source = createEntity(1L, "h1", "global", "v1");
   
    List<HostConfigMappingEntity> target = hostConfigMappingDAO.findByType(1L, "h1", "global");

    Assert.assertEquals("Expected one result", 1, target.size());
    Assert.assertEquals("Expected version 'v1'", source.getVersion(), target.get(0).getVersion());
  }
View Full Code Here

    Assert.assertEquals("Expected version 'v1'", source.getVersion(), target.get(0).getVersion());
  }
 
  @Test
  public void testMerge() throws Exception {
    HostConfigMappingEntity source = createEntity(1L, "h1", "global", "v1");
   
    List<HostConfigMappingEntity> target = hostConfigMappingDAO.findByType(1L, "h1", "global");

    Assert.assertEquals("Expected one result", 1, target.size());
    Assert.assertEquals("Expected version 'v1'", source.getVersion(), target.get(0).getVersion());
    Assert.assertEquals("Expected selected flag 1", 1, target.get(0).isSelected());
   
    HostConfigMappingEntity toChange = target.get(0);
   
    toChange.setSelected(0);
   
    hostConfigMappingDAO.merge(toChange);
   
    target = hostConfigMappingDAO.findByType(1L, "h1", "global");
View Full Code Here

  }
 
  @Test
  public void testFindSelected() throws Exception {
    createEntity(1L, "h1", "global", "version1");
    HostConfigMappingEntity entity2 = createEntity(1L, "h1", "core-site", "version1");
   
    List<HostConfigMappingEntity> targets = hostConfigMappingDAO.findSelected(1L, "h1");
    Assert.assertEquals("Expected two entities", 2, targets.size());
   
    entity2.setSelected(0);
    hostConfigMappingDAO.merge(entity2);
   
    createEntity(1L, "h1", "core-site", "version2");

    targets = hostConfigMappingDAO.findSelected(1L, "h1");
View Full Code Here

    Assert.assertEquals("Expected two entities", 2, targets.size());
  }
 
  @Test
  public void testFindSelectedByType() throws Exception {
    HostConfigMappingEntity entity1 = createEntity(1L, "h1", "global", "version1");
   
    HostConfigMappingEntity target = hostConfigMappingDAO.findSelectedByType(1L, "h1", "core-site");
    Assert.assertNull("Expected null entity for type 'core-site'", target);
   
    target = hostConfigMappingDAO.findSelectedByType(1L, "h1", "global");
    Assert.assertNotNull("Expected non-null entity for type 'global'", target);
    Assert.assertEquals("Expected version to be '" + entity1.getVersion() + "'", entity1.getVersion(), target.getVersion());
   
    target.setSelected(0);
    hostConfigMappingDAO.merge(target);
   
    HostConfigMappingEntity entity2 = createEntity(1L, "h1", "global", "version2");
   
    target = hostConfigMappingDAO.findSelectedByType(1L, "h1", "global");
    Assert.assertNotNull("Expected non-null entity for type 'global'", target);
   
    Assert.assertEquals("Expected version to be '" + entity2.getVersion() + "'", entity2.getVersion(), target.getVersion());
   
    Assert.assertEquals("Expected instance equality", entity2, target);
  }
View Full Code Here

    Assert.assertEquals("Expected instance equality", entity2, target);
  }
 
  @Test
  public void testFindSelectedHostsByType() throws Exception {
    HostConfigMappingEntity entity1 = createEntity(1L, "h1", "global", "v1");
    HostConfigMappingEntity entity2 = createEntity(1L, "h2", "global", "v1");
   
    List<HostConfigMappingEntity> list = hostConfigMappingDAO.findSelectedHostsByType(1L, "global");
    Assert.assertEquals("Expected two hosts", 2, list.size());
   
    entity2.setSelected(0);
    hostConfigMappingDAO.merge(entity2);
   
    list = hostConfigMappingDAO.findSelectedHostsByType(1L, "global");
    Assert.assertEquals("Expected one host", 1, list.size());
   
View Full Code Here

  @Transactional
  public boolean addDesiredConfig(long clusterId, boolean selected, String user, Config config) {
    if (null == user)
      throw new NullPointerException("User must be specified.");
   
    HostConfigMappingEntity exist = getDesiredConfigEntity(clusterId, config.getType());
    if (null != exist && exist.getVersion().equals(config.getVersionTag())) {
      if (!selected) {
        exist.setSelected(0);
        hostConfigMappingDAO.merge(exist);
      }
      return false;
    }
   
    writeLock.lock();
   
    try {
      // set all old mappings for this type to empty
      for (HostConfigMappingEntity e : hostConfigMappingDAO.findByType(clusterId,
          hostEntity.getHostName(), config.getType())) {
        e.setSelected(0);
        hostConfigMappingDAO.merge(e);
      }
     
      HostConfigMappingEntity entity = new HostConfigMappingEntity();
      entity.setClusterId(Long.valueOf(clusterId));
      entity.setCreateTimestamp(Long.valueOf(System.currentTimeMillis()));
      entity.setHostName(hostEntity.getHostName());
      entity.setSelected(1);
      entity.setUser(user);
      entity.setType(config.getType());
      entity.setVersion(config.getVersionTag());
     
      hostConfigMappingDAO.create(entity);
    }
    finally {
      writeLock.unlock();
View Full Code Here

  @Transactional
  public boolean addDesiredConfig(long clusterId, boolean selected, String user, Config config) {
    if (null == user)
      throw new NullPointerException("User must be specified.");
   
    HostConfigMappingEntity exist = getDesiredConfigEntity(clusterId, config.getType());
    if (null != exist && exist.getVersion().equals(config.getVersionTag())) {
      if (!selected) {
        exist.setSelected(0);
        hostConfigMappingDAO.merge(exist);
      }
      return false;
    }
   
    writeLock.lock();
   
    try {
      // set all old mappings for this type to empty
      for (HostConfigMappingEntity e : hostConfigMappingDAO.findByType(clusterId,
          hostEntity.getHostName(), config.getType())) {
        e.setSelected(0);
        hostConfigMappingDAO.merge(e);
      }
     
      HostConfigMappingEntity entity = new HostConfigMappingEntity();
      entity.setClusterId(Long.valueOf(clusterId));
      entity.setCreateTimestamp(Long.valueOf(System.currentTimeMillis()));
      entity.setHostName(hostEntity.getHostName());
      entity.setSelected(1);
      entity.setUser(user);
      entity.setType(config.getType());
      entity.setVersion(config.getVersionTag());
     
      hostConfigMappingDAO.create(entity);
    }
    finally {
      writeLock.unlock();
View Full Code Here

   
  }

  public HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping) {
   
    HostConfigMappingEntity hostConfigMappingEntity = new HostConfigMappingEntity();
   
    hostConfigMappingEntity.setClusterId(hostConfigMapping.getClusterId());
    hostConfigMappingEntity.setCreateTimestamp(hostConfigMapping.getCreateTimestamp());
    hostConfigMappingEntity.setHostName(hostConfigMapping.getHostName());
    hostConfigMappingEntity.setSelected(hostConfigMapping.getSelected());
    hostConfigMappingEntity.setServiceName(hostConfigMapping.getServiceName());
    hostConfigMappingEntity.setType(hostConfigMapping.getType());
    hostConfigMappingEntity.setUser(hostConfigMapping.getUser());
    hostConfigMappingEntity.setVersion(hostConfigMapping.getVersion());
   
    return hostConfigMappingEntity;
  }
View Full Code Here

 
  @Override
  @Transactional
  public void addDesiredConfig(long clusterId, boolean selected, Config config) {
   
    HostConfigMappingEntity exist = getDesiredConfigEntity(clusterId, config.getType());
    if (null != exist && exist.getVersion().equals(config.getVersionTag())) {
      if (!selected) {
        exist.setSelected(0);
        hostConfigMappingDAO.merge(exist);
      }
      return;
    }
   
    writeLock.lock();     
   
    try {
      // set all old mappings for this type to empty
      for (HostConfigMappingEntity e : hostConfigMappingDAO.findByType(clusterId,
          hostEntity.getHostName(), config.getType())) {
        e.setSelected(0);
        hostConfigMappingDAO.merge(e);
      }
     
      HostConfigMappingEntity entity = new HostConfigMappingEntity();
      entity.setClusterId(Long.valueOf(clusterId));
      entity.setCreateTimestamp(Long.valueOf(new Date().getTime()));
      entity.setHostName(hostEntity.getHostName());
      entity.setSelected(1);
      entity.setType(config.getType());
      entity.setVersion(config.getVersionTag());
     
      hostConfigMappingDAO.create(entity);
    }
    finally {
      writeLock.unlock();
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.orm.entities.HostConfigMappingEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.