Package org.apache.ambari.server.state

Examples of org.apache.ambari.server.state.Config


    // Create Config group for core-site
    configs = new HashMap<String, String>();
    configs.put("a", "c");
    Cluster cluster = clusters.getCluster(clusterName);
    final Config config = new ConfigImpl("core-site");
    config.setProperties(configs);
    config.setVersionTag("version122");
    Long groupId = createConfigGroup(cluster, "g1", "t1",
      new ArrayList<String>() {{ add("h1"); }},
      new ArrayList<Config>() {{ add(config); }});

    Assert.assertNotNull(groupId);

    // Create Config group for mapred-site
    configs = new HashMap<String, String>();
    configs.put("a", "c");

    final Config config2 = new ConfigImpl("mapred-site");
    config2.setProperties(configs);
    config2.setVersionTag("version122");
    groupId = createConfigGroup(cluster, "g2", "t2",
      new ArrayList<String>() {{ add("h1"); }},
      new ArrayList<Config>() {{ add(config2); }});

    Assert.assertNotNull(groupId);
View Full Code Here


    // Create Config group for hdfs-site
    configs = new HashMap<String, String>();
    configs.put("a", "c");

    final Config config = new ConfigImpl("hdfs-site");
    config.setProperties(configs);
    config.setVersionTag("version122");
    Long groupId = createConfigGroup(clusters.getCluster(clusterName), "g1", "t1",
        new ArrayList<String>() {{
          add("h1");
          add("h2");
        }},
View Full Code Here

    // Create Config group for hdfs-site
    configs = new HashMap<String, String>();
    configs.put("a", "c");

    final Config config = new ConfigImpl("hdfs-site");
    config.setProperties(configs);
    config.setVersionTag("version122");
    Long groupId = createConfigGroup(clusters.getCluster(clusterName), "g1", "t1",
      new ArrayList<String>() {{ add("h1"); add("h2"); }},
      new ArrayList<Config>() {{ add(config); }});

    Assert.assertNotNull(groupId);
View Full Code Here

    // test null map with no prior
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v1", null));
    controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
    Config config = cluster.getDesiredConfigByType("typeA");
    Assert.assertNull(config);
   
    // test empty map with no prior
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v1", new HashMap<String, String>()));
    controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
    config = cluster.getDesiredConfigByType("typeA");
    Assert.assertNotNull(config);
   
    // test empty properties on a new version
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v2", new HashMap<String, String>()));
    controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
    config = cluster.getDesiredConfigByType("typeA");
    Assert.assertNotNull(config);
    Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(config.getProperties().size()));
   
    // test new version
    Map<String, String> map = new HashMap<String, String>();
    map.clear();
    map.put("c", "d");
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v3", map));
    controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
    config = cluster.getDesiredConfigByType("typeA");
    Assert.assertNotNull(config);
    Assert.assertTrue(config.getProperties().containsKey("c"));
   
    // test reset to v2
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v2", new HashMap<String, String>()));
    controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
    config = cluster.getDesiredConfigByType("typeA");
    Assert.assertEquals("v2", config.getVersionTag());
    Assert.assertNotNull(config);
    Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(config.getProperties().size()));
   
    // test v2, but with properties
    cr.setDesiredConfig(
        new ConfigurationRequest(clusterName, "typeA", "v2", new HashMap<String, String>() {{ put("a", "b"); }}));
    try {
View Full Code Here

    Map<String, Config> configs = new HashMap<String, Config>();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("a", "a1");
    properties.put("b", "b1");

    Config c1 = new ConfigImpl(cluster, "hdfs-site", properties, injector);
    properties.put("c", "c1");
    properties.put("d", "d1");
    Config c2 = new ConfigImpl(cluster, "core-site", properties, injector);
    Config c3 = new ConfigImpl(cluster, "foo-site", properties, injector);

    Map<String, String> mapRequestProps = new HashMap<String, String>();
    mapRequestProps.put("context", "Called from a test");

    c1.setVersionTag("v1");
    c2.setVersionTag("v1");
    c3.setVersionTag("v1");

    cluster.addConfig(c1);
    cluster.addConfig(c2);
    cluster.addConfig(c3);
    c1.persist();
    c2.persist();
    c3.persist();

    configs.put(c1.getType(), c1);
    configs.put(c2.getType(), c2);
    s1.updateDesiredConfigs(configs);
    s1.persist();
View Full Code Here

    Cluster cluster = clusters.getCluster("c1");
    cluster.setDesiredStackVersion(new StackId("HDP-0.1"));
   
    ConfigFactory cf = injector.getInstance(ConfigFactory.class);
    Config config1 = cf.createNew(cluster, "global",
        new HashMap<String, String>(){{ put("key1", "value1"); }});
    config1.setVersionTag("version1");

    Config config2 = cf.createNew(cluster, "core-site",
        new HashMap<String, String>(){{ put("key1", "value1"); }});
    config2.setVersionTag("version1");
   
    cluster.addConfig(config1);
    cluster.addConfig(config2);
    cluster.addDesiredConfig("_test", config1);
    cluster.addDesiredConfig("_test", config2);
View Full Code Here

        request.getType());
    if (null == configs) {
      configs = new HashMap<String, Config>();
    }

    Config config = configs.get(request.getVersionTag());
    if (configs.containsKey(request.getVersionTag())) {
      throw new AmbariException("Configuration with that tag exists for '"
          + request.getType() + "'");
    }

    config = configFactory.createNew (cluster, request.getType(),
        request.getProperties());
    config.setVersionTag(request.getVersionTag());

    config.persist();

    cluster.addConfig(config);
  }
View Full Code Here

    Set<ConfigurationResponse> responses = new HashSet<ConfigurationResponse>();

    // !!! if only one, then we need full properties
    if (null != request.getType() && null != request.getVersionTag()) {
      Config config = cluster.getConfig(request.getType(),
          request.getVersionTag());
      if (null != config) {
        ConfigurationResponse response = new ConfigurationResponse(
            cluster.getClusterName(), config.getType(), config.getVersionTag(),
            config.getProperties());
        responses.add(response);
      }
    }
    else {
      if (null != request.getType()) {
        Map<String, Config> configs = cluster.getConfigsByType(
            request.getType());

        if (null != configs) {
          for (Entry<String, Config> entry : configs.entrySet()) {
            ConfigurationResponse response = new ConfigurationResponse(
                cluster.getClusterName(), request.getType(),
                entry.getValue().getVersionTag(), new HashMap<String, String>());
            responses.add(response);
          }
        }
      } else {
        // !!! all configuration
        Collection<Config> all = cluster.getAllConfigs();

        for (Config config : all) {
          ConfigurationResponse response = new ConfigurationResponse(
             cluster.getClusterName(), config.getType(), config.getVersionTag(),
             new HashMap<String, String>());

          responses.add(response);
        }
      }
View Full Code Here

      if (null != cr.getProperties() && cr.getProperties().size() > 0) {
        cr.setClusterName(cluster.getClusterName());
        createConfiguration(cr);
      }

      Config baseConfig = cluster.getConfig(cr.getType(), cr.getVersionTag());
      if (null != baseConfig) {
        Config oldConfig = cluster.getDesiredConfigByType(cr.getType());
        String authName = getAuthName();
        if (cluster.addDesiredConfig(authName, baseConfig)) {
          Logger logger = LoggerFactory.getLogger("configchange");
          logger.info("cluster '" + request.getClusterName() + "' "
              + "changed by: '" + authName + "'; "
              + "type='" + baseConfig.getType() + "' "
              + "tag='" + baseConfig.getVersionTag() + "'"
              + (null == oldConfig ? "" : " from='"+ oldConfig.getVersionTag() + "'"));
        }
      }
    }

    StackId currentVersion = cluster.getCurrentStackVersion();
View Full Code Here

    for (Entry<String, DesiredConfig> entry : cluster.getDesiredConfigs().entrySet()) {
      String type = entry.getKey();
      String tag = entry.getValue().getVersion();
      // 1) start with cluster config
      Config config = cluster.getConfig(type, tag);

      if (null == config)
        continue;

      Map<String, String> props = new HashMap<String, String>(config.getProperties());
      Map<String, String> tags = new HashMap<String, String>();
      tags.put("tag", config.getVersionTag());

      // 2) apply the service overrides, if any are defined with different tags
      Service service = cluster.getService(serviceName);
      Config svcConfig = service.getDesiredConfigs().get(type);
      if (null != svcConfig && !svcConfig.getVersionTag().equals(tag)) {
        props.putAll(svcConfig.getProperties());
      }

      // 3) apply the host overrides, if any
      Host host = clusters.getHost(hostName);
      DesiredConfig dc = host.getDesiredConfigs(cluster.getClusterId()).get(type);
      if (null != dc) {
        Config hostConfig = cluster.getConfig(type, dc.getVersion());
        if (null != hostConfig) {
          props.putAll(hostConfig.getProperties());
          tags.put("host_override_tag", hostConfig.getVersionTag());
        }
      }
     
      configurations.put(type, props);
      configTags.put(type, tags);
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.state.Config

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.