Package org.apache.stratos.lb.common.conf.structure

Examples of org.apache.stratos.lb.common.conf.structure.Node


    }

    public final void testBuildNode() {

        // Testing a node only has properties
        Node a = new Node();
        a.setName("loadbalancer");

        content =
            "securityGroups      stratos-appserver-lb;\ninstanceType        m1.large;\n"
                + "instances           1;\nelasticIP           ${ELASTIC_IP};\n"
                + "availabilityZone    us-east-1c;\npayload             /mnt/payload.zip;";

        a = NodeBuilder.buildNode(a, content);

        assertEquals("loadbalancer", a.getName());
        assertEquals("stratos-appserver-lb", a.getProperty("securityGroups"));
        assertEquals("${ELASTIC_IP}", a.getProperty("elasticIP"));
        assertEquals("/mnt/payload.zip", a.getProperty("payload"));
        assertNull(a.getProperty("payloader"));

        // Testing a node has sub nodes and properties
        a = new Node();
        a.setName("appserver");

        content =
            "hosts                   appserver.cloud-test.wso2.com,as.cloud-test.wso2.com;\n"
                + "domains   {\n" + "wso2.as1.domain {\n" + "tenant_range    1-100;\n" + "}\n"
                + "wso2.as2.domain {\n" + "tenant_range    101-200;\n" + "}\n"
                + "wso2.as3.domain { # domain\n" + "tenant_range    *;\n" + "}\n" + "}\n"
                + "# line comment \n"
                + "payload                 resources/cluster_node.zip;# payload\n"
                + "availability_zone       us-east-1c;\n";

        a = NodeBuilder.buildNode(a, content);

        assertEquals("appserver", a.getName());
        assertEquals(1, a.getChildNodes().size());
        assertEquals("domains", a.getChildNodes().get(0).getName());
        assertEquals("appserver.cloud-test.wso2.com,as.cloud-test.wso2.com",
                            a.getProperty("hosts"));
        assertEquals("resources/cluster_node.zip", a.getProperty("payload"));
        assertEquals(null, a.getProperty("payloader"));

        Node b = a.getChildNodes().get(0);

        assertEquals(3, b.getChildNodes().size());
        assertEquals(null, b.getProperty("payload"));

        Node c = b.getChildNodes().get(0);

        assertEquals(0, c.getChildNodes().size());
        assertEquals("1-100", c.getProperty("tenant_range"));

        c = b.getChildNodes().get(2);

        assertEquals(0, c.getChildNodes().size());
        assertEquals("*", c.getProperty("tenant_range"));
       
        String nodeStr = "appserver {\n" +
                "\thosts\tappserver.cloud-test.wso2.com,as.cloud-test.wso2.com;\n" +
                "\tpayload\tresources/cluster_node.zip;\n" +
            "\tavailability_zone\tus-east-1c;\n" +
            "\tdomains {\n" +
            "\t\twso2.as1.domain {\n" +
            "\t\t\ttenant_range\t1-100;\n" +
            "\t\t}\n" +
            "\t\twso2.as2.domain {\n" +
            "\t\t\ttenant_range\t101-200;\n" +
            "\t\t}\n" +
            "\t\twso2.as3.domain {\n" +
            "\t\t\ttenant_range\t*;\n" +
            "\t\t}\n" +
            "\t}\n" +
            "}";
       
        assertEquals(nodeStr, a.toString());
       
        // test equals method
        assertEquals(true, a.equals(a));
        assertEquals(false, a.equals(b));
        assertEquals(false, c.equals(b));
       
        // test buildNode(String)
        c = NodeBuilder.buildNode(nodeStr);
       
        assertEquals(c.getName(), "appserver");
        assertEquals(c.getChildNodes().size(), 1);
        assertEquals(c.getProperty("availability_zone"), "us-east-1c");

    }
View Full Code Here


            log.error(msg, e);
            throw new RuntimeException(msg, e);
        }

        // build a Node object for whole loadbalancer.conf
        rootNode = new Node();
        rootNode.setName("root");
        rootNode = NodeBuilder.buildNode(rootNode, lbConfigString);

        // load 'loadbalancer' node
        Node lbConfigNode = rootNode.findChildNodeByName(Constants.LOAD_BALANCER_ELEMENT);

        if(lbConfigNode != null){
          createConfiguration(lbConfig = new LBConfiguration(), lbConfigNode);
        }

        // load services node
        Node servicesConfigNode = rootNode.findChildNodeByName(Constants.SERVICES_ELEMENT);

        if (servicesConfigNode == null) {
            String msg = "Mandatory " + Constants.SERVICES_ELEMENT +
                    " element can not be found in the configuration file.";
            log.error(msg);
View Full Code Here

        // current list of service configs
        List<ServiceConfiguration> currentServiceConfigs = new ArrayList<ServiceConfiguration>();
       
        // Building default configuration
        Node defaultNode = servicesConfigNode.findChildNodeByName(Constants.DEFAULTS_ELEMENT);

        if (defaultNode != null) {

            createConfiguration(defaultServiceConfig = new ServiceConfiguration(), defaultNode);
        }

        // Building custom services configuration
        for (Node serviceNode : servicesConfigNode.getChildNodes()) {
            //skip default node
            if (serviceNode != defaultNode) {

                String serviceName = serviceNode.getName();

                // reading domains

                Node domainsNode;

                if (serviceNode.getChildNodes().isEmpty() ||
                        !(domainsNode = serviceNode.getChildNodes().get(0)).getName().equals(
                                Constants.DOMAIN_ELEMENT)) {

                    String msg = "The mandatory domains element, child of the " + serviceName +
                            " element is not specified in the configuration file. \n"+
                            serviceNode.toString();
                    log.error(msg);
                    throw new RuntimeException(msg);
                }

                if (domainsNode.getChildNodes().isEmpty()) {
                    // this is probably a mistake, so we don't proceed
                    String msg = "No domain is specified under " + Constants.DOMAIN_ELEMENT +
                            " of " + serviceName + " element.";
                    log.error(msg);
                    throw new RuntimeException(msg);
                }

                ServiceConfiguration serviceConfig;

                // iterates through all the service domain specified in this service element.
                for (Node domain : domainsNode.getChildNodes()) {

                    // create a new service configuration
                    serviceConfig = new ServiceConfiguration();

                    // set service name
View Full Code Here

                    // reset the previous message
//                    data.setPreviousMsg(message);

                    // build the nginx format of this message, and get the Node object
                    Node topologyNode = NodeBuilder.buildNode(message);

                    // reset service configurations
//                    lbconfig.resetData();
                    // create new service configurations
                    List<ServiceConfiguration> currentServiceConfigs = lbconfig.createServicesConfig(topologyNode);
View Full Code Here

  @Override
  public Object getHostContexts(String config) {

    // build a Node object for whole loadbalancer.conf
    Node rootNode = new Node();
    rootNode.setName(Constants.SERVICES_ELEMENT);
    rootNode = NodeBuilder.buildNode(rootNode, config);

    LoadBalancerConfiguration.getInstance().createServicesConfig(rootNode);

    return LoadBalancerConfiguration.getInstance().getHostContextMap();
View Full Code Here

                obj = sharedQueue.take();
                msg = (String) obj;

                ConfigHolder data = ConfigHolder.getInstance();

                Node topologyNode = NodeBuilder.buildNode(msg);

                List<ServiceConfiguration> currentServiceConfigs = lbconfig.createServicesConfig(topologyNode);

                data.setServiceConfigs(lbconfig.getServiceNameToServiceConfigurations());
                generateGroupMgtAgents(lbconfig);
View Full Code Here

                @SuppressWarnings("unchecked")
                    List<ServiceContext> ctxts = (List<ServiceContext>) obj;
               
                for (ServiceContext serviceContext : ctxts) {

                  Node newNode = serviceContext.toNode();
                 
                  if(!topologyFile.exists()){
                    FileUtils.writeStringToFile(topologyFile, "services {\n}");
                  }
                 
                  String currentContent = FileUtils.readFileToString(topologyFile);
                  Node currentNode = NodeBuilder.buildNode(currentContent);
                        
                  for (Node aNode : currentNode.getChildNodes()) {
                    // similar service element is present
                          if(aNode.getName().equals(newNode.getName())){
                            // hence, we should not override, but append
                            Node domainsNode = aNode.findChildNodeByName(Constants.DOMAIN_ELEMENT);
                           
                            if(domainsNode == null){
                              // existing node is useless
                              currentNode.removeChildNode(aNode.getName());
                              currentNode.appendChild(newNode);
                              break;
                            }
                           
                            // append the new node/s
                            for (Node serNode : newNode.findChildNodeByName(Constants.DOMAIN_ELEMENT).getChildNodes()) {
                                 
                              for (Node currentSerNode : domainsNode.getChildNodes()) {
                                      String prop = Constants.SUB_DOMAIN_ELEMENT;
                                if(serNode.getName().equals(currentSerNode.getName()) &&
                                    serNode.getProperty(prop).equals(currentSerNode.getProperty(prop))){
                                  // if domain and sub domain, are not unique, we shouldn't append, but override
                                  domainsNode.removeChildNode(currentSerNode.getName());
                                  break;
                                }
                                    }
                             
                              domainsNode.appendChild(serNode);
                                }
                            isAdded = true;
                            break;
                          }
                        }
View Full Code Here

  }
 
  public static void removeTopologyAndPublish(ServiceContext serviceContext){
     
      Node currentNodeToBeRemoved = null;
      Node nodeToBeRemoved = serviceContext.toNode();
       
        if(!topologyFile.exists()){
            return;
        }
        try{
        String currentContent = FileUtils.readFileToString(topologyFile);
        Node currentNode = NodeBuilder.buildNode(currentContent);
           
        for (Node aNode : currentNode.getChildNodes()) {
            // similar service element is present
            if(aNode.getName().equals(nodeToBeRemoved.getName())){
                // let's check whether the domain node exists
               
                Node domainsNode = aNode.findChildNodeByName(Constants.DOMAIN_ELEMENT);
               
                if(domainsNode == null){
                    continue;
                }
               
                for (Node serNode : nodeToBeRemoved.findChildNodeByName(Constants.DOMAIN_ELEMENT).getChildNodes()) {
                   
                    for (Node currentSerNode : domainsNode.getChildNodes()) {
                        String prop = Constants.SUB_DOMAIN_ELEMENT;
                        if(serNode.getName().equals(currentSerNode.getName()) &&
                                serNode.getProperty(prop).equals(currentSerNode.getProperty(prop))){
                            // if domain and sub domain, are matching, we should remove the node.
                            domainsNode.removeChildNode(currentSerNode.getName());
                            if(domainsNode.getChildNodes().size() == 0){
                                // if no cluster definitions remain, we shouldn't keep the node
                                currentNodeToBeRemoved = aNode;
                            }
                            break;
                        }
View Full Code Here

                                        "</service>";
    return str;
  }
 
  public Node toNode() {
    Node node = new Node();
    node.setName(cartridgeType);
    String sbrace = Constants.NGINX_NODE_START_BRACE;
    String ebrace = Constants.NGINX_NODE_END_BRACE;
    String delimiter = Constants.NGINX_LINE_DELIMITER;
    String newLine = "\n";
    String nginx =
View Full Code Here

TOP

Related Classes of org.apache.stratos.lb.common.conf.structure.Node

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.