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

Examples of org.apache.stratos.lb.common.conf.util.HostContext


            // iterate through host names of this service
            for (String hostName : ((Set<String>) it.next())) {
                                                                 
                // building HostContext
                HostContext ctxt = new HostContext(hostName);

                // iterate through domains of this host
                for (Map.Entry<String, Map<String, ServiceConfiguration>> parentMap : serviceConfigurations.entrySet()) {

                    // iterate through sub domain of this domain
                    for (Map.Entry<String, ServiceConfiguration> childMap : parentMap.getValue()
                            .entrySet()) {
                        // iterate through hosts of this
                        for (String host : childMap.getValue().getHosts()) {
                            // if a matching Service configuration is found.
                            if (host.equals(hostName)) {
                               
                                String tenantRange = childMap.getValue().getTenantRange();
                                String domain = parentMap.getKey();
                                String subDomain = childMap.getKey();
                                         
                                ctxt.addTenantDomainContexts(LoadBalancerConfigUtil.getTenantDomainContexts(tenantRange, domain, subDomain));

                                break;
                            }
                        }
                       
                        //iterate through URL suffixes
                        for(Map.Entry<String, String> entry : childMap.getValue().getUrl_suffix().entrySet()) {
                            if(entry.getKey().equals(hostName)) {
                               
                                ctxt.setUrlSuffix(entry.getValue());
                               
                                break;
                            }

                        }
View Full Code Here


        }
        return false;
    }

    public Member getNextApplicationMember(String host, int tenantId) {
        HostContext hostContext = getHostContext(host);

        if(hostContext == null){
            String msg = "Invalid host name : " + host;
            log.error(msg);
            throw new SynapseException(msg);
        }

        // here we have to pass tenant id to get domain from hostContext
        String domain = hostContext.getDomainFromTenantId(tenantId);
        String subDomain = hostContext.getSubDomainFromTenantId(tenantId);

        LoadbalanceAlgorithm algorithm = hostContext.getAlgorithm();
        GroupManagementAgent groupMgtAgent = clusteringAgent.getGroupManagementAgent(domain, subDomain);
       
        if (groupMgtAgent == null) {
          String tenantDomain;
            try {
              tenantDomain = ConfigHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
            } catch (UserStoreException ignore) {
              tenantDomain = ""+tenantId;
            }
         
            String msg =
                    "No Group Management Agent found for the domain: " + domain + ", subDomain: "
                        + subDomain + ", host: " + host+ " and for tenant: "
                        +  tenantDomain;
            log.error(msg);
            throw new SynapseException(msg);
        }
        algorithm.setApplicationMembers(groupMgtAgent.getMembers());
        AlgorithmContext context = hostContext.getAlgorithmContext();
        return algorithm.getNextApplicationMember(context);
    }
View Full Code Here

        AlgorithmContext context = hostContext.getAlgorithmContext();
        return algorithm.getNextApplicationMember(context);
    }

    public HostContext getHostContext(String host) {
        HostContext hostContext = hostContextsMap.get(host);
        if (hostContext == null) {
            int indexOfDot;
            if ((indexOfDot = host.indexOf(".")) != -1) {
                hostContext = getHostContext(host.substring(indexOfDot + 1));
            }
View Full Code Here

    @Override
    public void addClusterDomain(ClusterDomain cluster) {

        // create group management agent, if one doesn't exist already.
        HostContext hostCtxt = createGroupMgtAgentIfNotExists(cluster);

        // we should only update if the above step is successful.
        if (hostCtxt != null) {
            // create / update Service Configuration
            createOrUpdateServiceConfig(cluster, hostCtxt);
View Full Code Here

            String msg = "TenantLoadBalanceMembershipHandler is null. Thus, We cannot proceed.";
            log.error(msg);
            throw new SynapseException(msg);
        }

        HostContext hostCtxt;

        // if there's an already registered HostContext use it
        if((hostCtxt = handler.getHostContext(hostName)) == null){
            hostCtxt = new HostContext(hostName);
        }
       
        List<TenantDomainContext> ctxts;
        ctxts = new ArrayList<TenantDomainContext>(hostCtxt.getTenantDomainContexts());

        // default value is super tenant mode - which is defined by tenant id 0, in this context
        int tenantId = 0;
        if(!"*".equals(tenantRange)){
          tenantId = Integer.parseInt(tenantRange);
        }
               
        ctxts.add(new TenantDomainContext(tenantId, domain, subDomain));

        hostCtxt.addTenantDomainContexts(ctxts);

        handler.addHostContext(hostCtxt);

        return hostCtxt;
    }
View Full Code Here

        String domain = null, subDomain = null;
       
        log.debug("************ Target Host: "+targetHost + " -- Tenant id : "+tenantId);

        HostContext ctxt = hostCtxts.get(targetHost);
       
        if (ctxt == null) {

            DomainMapping domainMapping = mappingCache.getMapping(targetHost);
            if (domainMapping == null) {
                registryManager = new RegistryManager();
                domainMapping = registryManager.getMapping(targetHost);
                mappingCache.addValidMapping(targetHost, domainMapping);
            }
            if (domainMapping != null) {

                String actualHost = domainMapping.getActualHost();

                // get the HostContext from the actual host name in the case of domain
                // mapping.
                ctxt = hostCtxts.get(actualHost);

            }
        }

        if (ctxt == null) {
            log.debug("Host Context is null.");
          // we don't need to do anything
          return true;
        }


        // gets the corresponding domain
        domain = ctxt.getDomainFromTenantId(tenantId);
        synCtx.setProperty(AutoscaleConstants.TARGET_DOMAIN, domain);

        // gets the corresponding sub domain
        subDomain = ctxt.getSubDomainFromTenantId(tenantId);
        synCtx.setProperty(AutoscaleConstants.TARGET_SUB_DOMAIN, subDomain);

        if (appDomainContexts.get(domain) == null) {
            // if we do not find a correct context, we just ignore
            log.debug("AppDomainContext not found for domain " + domain);
View Full Code Here

TOP

Related Classes of org.apache.stratos.lb.common.conf.util.HostContext

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.