Package org.apache.ambari.server.orm.dao

Examples of org.apache.ambari.server.orm.dao.ClusterDAO


    );
  }

  @Transactional
  public void updateStackDetails(String stackName, String stackVersion) {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    List<Long> clusterIds = new ArrayList<Long>();

    List<ClusterEntity> clusterEntities = clusterDAO.findAll();
    if (clusterEntities != null && !clusterEntities.isEmpty()) {
      for (ClusterEntity entity : clusterEntities) {
        clusterIds.add(entity.getClusterId());
        String stackIdString = entity.getDesiredStackVersion();
        entity.setDesiredStackVersion(getStackIdString(stackIdString,
          stackName, stackVersion));
        clusterDAO.merge(entity);
      }
    }

    ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class);
View Full Code Here


    //create cluster state entities if not present
    executeInTransaction(new Runnable() {
      @Override
      public void run() {
        ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
        ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class);
        List<ClusterEntity> clusterEntities = clusterDAO.findAll();
        for (ClusterEntity clusterEntity : clusterEntities) {
          if (clusterStateDAO.findByPK(clusterEntity.getClusterId()) == null) {
            ClusterStateEntity clusterStateEntity = new ClusterStateEntity();
            clusterStateEntity.setClusterEntity(clusterEntity);
            clusterStateEntity.setCurrentStackVersion(clusterEntity.getDesiredStackVersion());

            clusterStateDAO.create(clusterStateEntity);

            clusterEntity.setClusterStateEntity(clusterStateEntity);

            clusterDAO.merge(clusterEntity);
          }
        }
      }
    });
   
View Full Code Here

      }
    });
  }

  protected void addHistoryServer() {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
    ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
   
    List<ClusterEntity> clusterEntities = clusterDAO.findAll();
    for (final ClusterEntity clusterEntity : clusterEntities) {
      ServiceComponentDesiredStateEntityPK pkHS = new ServiceComponentDesiredStateEntityPK();
      pkHS.setComponentName("HISTORYSERVER");
      pkHS.setClusterId(clusterEntity.getClusterId());
      pkHS.setServiceName("MAPREDUCE");
View Full Code Here

    final String log4jConfigTypeContains = "log4j";
    final String defaultVersionTag = "version1";
    final String defaultUser = "admin";

    LOG.debug("Adding missing configs into Ambari DB.");
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);

    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
    Gson gson = injector.getInstance(Gson.class);

    List <ClusterEntity> clusterEntities = clusterDAO.findAll();
    for (final ClusterEntity clusterEntity : clusterEntities) {
      Long clusterId = clusterEntity.getClusterId();
      String desiredStackVersion = clusterEntity.getDesiredStackVersion();

      Map<String, String> clusterInfo =
        gson.<Map<String, String>>fromJson(desiredStackVersion, Map.class);

      String stackName = clusterInfo.get("stackName");
      String stackVersion = clusterInfo.get("stackVersion");

      List<ClusterServiceEntity> clusterServiceEntities = clusterServiceDAO.findAll();
      for (final ClusterServiceEntity clusterServiceEntity : clusterServiceEntities) {
        String serviceName = clusterServiceEntity.getServiceName();
        ServiceInfo serviceInfo = null;
        try {
          serviceInfo = ambariMetaInfo.getService(stackName, stackVersion, serviceName);
        } catch (AmbariException e) {
          LOG.error("Service " + serviceName + " not found for " + stackName + stackVersion);
          continue;
        }
        List<String> configTypes = serviceInfo.getConfigDependencies();
        if (configTypes != null) {
          for (String configType : configTypes) {
            if (configType.contains(log4jConfigTypeContains)) {
              ClusterConfigEntityPK configEntityPK = new ClusterConfigEntityPK();
              configEntityPK.setClusterId(clusterId);
              configEntityPK.setType(configType);
              configEntityPK.setTag(defaultVersionTag);
              ClusterConfigEntity configEntity = clusterDAO.findConfig(configEntityPK);

              if (configEntity == null) {
                String filename = configType + ".xml";
                Map<String, String> properties = new HashMap<String, String>();
                for (PropertyInfo propertyInfo : serviceInfo.getProperties()) {
                  if (filename.equals(propertyInfo.getFilename())) {
                    properties.put(propertyInfo.getName(), propertyInfo.getValue());
                  }
                }
                if (!properties.isEmpty()) {
                  String configData = gson.toJson(properties);
                  configEntity = new ClusterConfigEntity();
                  configEntity.setClusterId(clusterId);
                  configEntity.setType(configType);
                  configEntity.setTag(defaultVersionTag);
                  configEntity.setData(configData);
                  configEntity.setTimestamp(System.currentTimeMillis());
                  configEntity.setClusterEntity(clusterEntity);
                  LOG.debug("Creating new " + configType + " config...");
                  clusterDAO.createConfig(configEntity);

                  Collection<ClusterConfigMappingEntity> entities =
                    clusterEntity.getConfigMappingEntities();

                  ClusterConfigMappingEntity clusterConfigMappingEntity =
                    new ClusterConfigMappingEntity();
                  clusterConfigMappingEntity.setClusterEntity(clusterEntity);
                  clusterConfigMappingEntity.setClusterId(clusterId);
                  clusterConfigMappingEntity.setType(configType);
                  clusterConfigMappingEntity.setCreateTimestamp(
                    Long.valueOf(System.currentTimeMillis()));
                  clusterConfigMappingEntity.setSelected(1);
                  clusterConfigMappingEntity.setUser(defaultUser);
                  clusterConfigMappingEntity.setVersion(configEntity.getTag());
                  entities.add(clusterConfigMappingEntity);
                  clusterDAO.merge(clusterEntity);
                }
              }
            }

          }
View Full Code Here

    LOG.debug("Missing configs have been successfully added into Ambari DB.");
  }

  protected void processDecommissionedDatanodes() {
    KeyValueDAO keyValueDAO = injector.getInstance(KeyValueDAO.class);
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    Gson gson = injector.getInstance(Gson.class);
    HostComponentDesiredStateDAO desiredStateDAO = injector.getInstance
      (HostComponentDesiredStateDAO.class);

    KeyValueEntity keyValueEntity = keyValueDAO.findByKey("decommissionDataNodesTag");
    String value = null;
    if (keyValueEntity != null) {
      value = keyValueEntity.getValue();
      if (value != null && !value.isEmpty()) {
        List<ClusterEntity> clusterEntities = clusterDAO.findAll();
        for (ClusterEntity clusterEntity : clusterEntities) {
          Long clusterId = clusterEntity.getClusterId();
          ClusterConfigEntityPK configEntityPK = new ClusterConfigEntityPK();
          configEntityPK.setClusterId(clusterId);
          configEntityPK.setType("hdfs-exclude-file");
          configEntityPK.setTag(value.trim());
          ClusterConfigEntity configEntity = clusterDAO.findConfig(configEntityPK);
          if (configEntity != null) {
            String configData = configEntity.getData();
            if (configData != null) {
              Map<String, String> properties = gson.<Map<String, String>>fromJson(configData, Map.class);
              if (properties != null && !properties.isEmpty()) {
View Full Code Here

    );
  }

  @Transactional
  public void updateStackDetails(String stackName, String stackVersion) {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    List<Long> clusterIds = new ArrayList<Long>();

    List<ClusterEntity> clusterEntities = clusterDAO.findAll();
    if (clusterEntities != null && !clusterEntities.isEmpty()) {
      for (ClusterEntity entity : clusterEntities) {
        clusterIds.add(entity.getClusterId());
        String stackIdString = entity.getDesiredStackVersion();
        entity.setDesiredStackVersion(getStackIdString(stackIdString,
          stackName, stackVersion));
        clusterDAO.merge(entity);
      }
    }

    ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class);
View Full Code Here

    //create cluster state entities if not present
    executeInTransaction(new Runnable() {
      @Override
      public void run() {
        ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
        ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class);
        List<ClusterEntity> clusterEntities = clusterDAO.findAll();
        for (ClusterEntity clusterEntity : clusterEntities) {
          if (clusterStateDAO.findByPK(clusterEntity.getClusterId()) == null) {
            ClusterStateEntity clusterStateEntity = new ClusterStateEntity();
            clusterStateEntity.setClusterEntity(clusterEntity);
            clusterStateEntity.setCurrentStackVersion(clusterEntity.getDesiredStackVersion());

            clusterStateDAO.create(clusterStateEntity);

            clusterEntity.setClusterStateEntity(clusterStateEntity);

            clusterDAO.merge(clusterEntity);
          }
        }
      }
    });
   
View Full Code Here

      }
    });
  }

  protected void addHistoryServer() {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
    ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
   
    List<ClusterEntity> clusterEntities = clusterDAO.findAll();
    for (final ClusterEntity clusterEntity : clusterEntities) {
      ServiceComponentDesiredStateEntityPK pkHS = new ServiceComponentDesiredStateEntityPK();
      pkHS.setComponentName("HISTORYSERVER");
      pkHS.setClusterId(clusterEntity.getClusterId());
      pkHS.setServiceName("MAPREDUCE");
View Full Code Here

    final String log4jConfigTypeContains = "log4j";
    final String defaultVersionTag = "version1";
    final String defaultUser = "admin";

    LOG.debug("Adding missing configs into Ambari DB.");
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);

    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
    Gson gson = injector.getInstance(Gson.class);

    List <ClusterEntity> clusterEntities = clusterDAO.findAll();
    for (final ClusterEntity clusterEntity : clusterEntities) {
      Long clusterId = clusterEntity.getClusterId();
      String desiredStackVersion = clusterEntity.getDesiredStackVersion();

      Map<String, String> clusterInfo =
        gson.<Map<String, String>>fromJson(desiredStackVersion, Map.class);

      String stackName = clusterInfo.get("stackName");
      String stackVersion = clusterInfo.get("stackVersion");

      List<ClusterServiceEntity> clusterServiceEntities = clusterServiceDAO.findAll();
      for (final ClusterServiceEntity clusterServiceEntity : clusterServiceEntities) {
        String serviceName = clusterServiceEntity.getServiceName();
        ServiceInfo serviceInfo = null;
        try {
          serviceInfo = ambariMetaInfo.getService(stackName, stackVersion, serviceName);
        } catch (AmbariException e) {
          LOG.error("Service " + serviceName + " not found for " + stackName + stackVersion);
          continue;
        }
        List<String> configTypes = serviceInfo.getConfigDependencies();
        if (configTypes != null) {
          for (String configType : configTypes) {
            if (configType.contains(log4jConfigTypeContains)) {
              ClusterConfigEntityPK configEntityPK = new ClusterConfigEntityPK();
              configEntityPK.setClusterId(clusterId);
              configEntityPK.setType(configType);
              configEntityPK.setTag(defaultVersionTag);
              ClusterConfigEntity configEntity = clusterDAO.findConfig(configEntityPK);

              if (configEntity == null) {
                String filename = configType + ".xml";
                Map<String, String> properties = new HashMap<String, String>();
                for (PropertyInfo propertyInfo : serviceInfo.getProperties()) {
                  if (filename.equals(propertyInfo.getFilename())) {
                    properties.put(propertyInfo.getName(), propertyInfo.getValue());
                  }
                }
                if (!properties.isEmpty()) {
                  String configData = gson.toJson(properties);
                  configEntity = new ClusterConfigEntity();
                  configEntity.setClusterId(clusterId);
                  configEntity.setType(configType);
                  configEntity.setTag(defaultVersionTag);
                  configEntity.setData(configData);
                  configEntity.setTimestamp(System.currentTimeMillis());
                  configEntity.setClusterEntity(clusterEntity);
                  LOG.debug("Creating new " + configType + " config...");
                  clusterDAO.createConfig(configEntity);

                  Collection<ClusterConfigMappingEntity> entities =
                    clusterEntity.getConfigMappingEntities();

                  ClusterConfigMappingEntity clusterConfigMappingEntity =
                    new ClusterConfigMappingEntity();
                  clusterConfigMappingEntity.setClusterEntity(clusterEntity);
                  clusterConfigMappingEntity.setClusterId(clusterId);
                  clusterConfigMappingEntity.setType(configType);
                  clusterConfigMappingEntity.setCreateTimestamp(
                    Long.valueOf(System.currentTimeMillis()));
                  clusterConfigMappingEntity.setSelected(1);
                  clusterConfigMappingEntity.setUser(defaultUser);
                  clusterConfigMappingEntity.setVersion(configEntity.getTag());
                  entities.add(clusterConfigMappingEntity);
                  clusterDAO.merge(clusterEntity);
                }
              }
            }

          }
View Full Code Here

  public void tearDown() {
    injector.getInstance(PersistService.class).stop();
  }

  private ClusterEntity createCluster() {
    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
    ClusterEntity clusterEntity = new ClusterEntity();
    clusterEntity.setClusterId(1L);
    clusterEntity.setClusterName(CLUSTER_NAME);
    clusterEntity.setDesiredStackVersion(DESIRED_STACK_VERSION);
    clusterDAO.create(clusterEntity);
    return clusterEntity;
  }
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.orm.dao.ClusterDAO

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.