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

Examples of org.apache.stratos.lb.common.util.DomainMapping


    private Resource resource = null;
    public static final String HOST_INFO = "hostinfo/";
    public static final String ACTUAL_HOST = "actual.host";

    public DomainMapping getMapping(String hostName) {
        DomainMapping domainMapping;
        try {
            if (governanceRegistry.resourceExists(HOST_INFO + hostName)) {
                resource = governanceRegistry.get(HOST_INFO + hostName);
                domainMapping = new DomainMapping(hostName);
                domainMapping.setActualHost(resource.getProperty(ACTUAL_HOST));
                return domainMapping;
            }
        } catch (RegistryException e) {
            log.info("Error while getting registry resource");
            throw new RuntimeException(e);
View Full Code Here


            targetHost = targetHost.substring(0, targetHost.indexOf(':'));
        }
        //Gathering required information for domain mapping done

        boolean isValidHost = tlbMembershipHandler.isAValidHostName(targetHost);
        DomainMapping domainMapping = null;
        if(!isValidHost){
            //check if the host is valid, if not valid, execute following code to check whether it is a mapped domain
            domainMapping = mappingCache.getMapping(targetHost);
            if(domainMapping == null){
                registryManager = new RegistryManager();
                domainMapping = registryManager.getMapping(targetHost);
                mappingCache.addValidMapping(targetHost, domainMapping);
            }
            if (domainMapping != null) {
                actualHost = domainMapping.getActualHost();

                if(containsPort){
                    transportHeaders.put(HTTP.TARGET_HOST, actualHost + ":" + port);
                } else {
                    transportHeaders.put(HTTP.TARGET_HOST, actualHost);
                }
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty("TRANSPORT_HEADERS" , transportHeaders);

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

        if (isSessionAffinityBasedLB()) {
            // first check if this session is associated with a session. if so, get the endpoint
            // associated for that session.
            sessionInformation =
                    (SessionInformation) synCtx.getProperty(
                            SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);

            currentMember = (Member) synCtx.getProperty(
                    SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);

            if (sessionInformation == null && currentMember == null) {
                sessionInformation = dispatcher.getSession(synCtx);
                if (sessionInformation != null) {

                    if (log.isDebugEnabled()) {
                        log.debug("Current session id : " + sessionInformation.getId());
                    }

                    currentMember = sessionInformation.getMember();
                    synCtx.setProperty(
                            SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                    // This is for reliably recovery any session information if while response is getting ,
                    // session information has been removed by cleaner.
                    // This will not be a cost as  session information a not heavy data structure
                    synCtx.setProperty(
                            SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
                }
            }

        }

        // Dispatch request the relevant member
//        String targetHost = getTargetHost(synCtx);
        ConfigurationContext configCtx =
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();

        if (tlbMembershipHandler.getConfigurationContext() == null) {
            tlbMembershipHandler.setConfigurationContext(configCtx);
        }

        if(tlbMembershipHandler.getClusteringAgent() == null) {
            tlbMembershipHandler.setConfigurationContext(configCtx);
        }

        TenantDynamicLoadBalanceFaultHandlerImpl faultHandler = new TenantDynamicLoadBalanceFaultHandlerImpl();
        log.debug("************* Actual Host: "+actualHost +" ****** Target Host: "+targetHost);
        faultHandler.setHost(actualHost != null ? actualHost : targetHost);

        if (sessionInformation != null && currentMember != null) {
            //send message on current session
            sessionInformation.updateExpiryTime();
            sendToApplicationMember(synCtx, currentMember, faultHandler, false);
        } else {
//            prepare for a new session
            int tenantId = getTenantId(synCtx);
            //check if this is a valid host name registered in ELB
            if(tlbMembershipHandler.isAValidHostName(targetHost)){
                currentMember = tlbMembershipHandler.getNextApplicationMember(targetHost, tenantId);
                if (currentMember == null) {
                    String msg = "No application members available";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
                sendToApplicationMember(synCtx, currentMember, faultHandler, true);
            } else {
                if(domainMapping == null){
                    registryManager = new RegistryManager();
                    domainMapping = registryManager.getMapping(targetHost);
                    mappingCache.addValidMapping(targetHost, domainMapping);
                }
                if(domainMapping != null) {

                    actualHost = domainMapping.getActualHost();
                   
                    log.debug("************* Actual Host: "+actualHost +" ****** Target Host: "+targetHost);
                    faultHandler.setHost(actualHost != null ? actualHost : targetHost);

                    if(containsPort){
View Full Code Here

    private Resource resource = null;
    public static final String HOST_INFO = "hostinfo/";
    public static final String ACTUAL_HOST = "actual.host";

    public DomainMapping getMapping(String hostName) {
        DomainMapping domainMapping;
        try {
            if (governanceRegistry.resourceExists(HOST_INFO + hostName)) {
                resource = governanceRegistry.get(HOST_INFO + hostName);
                domainMapping = new DomainMapping(hostName);
                domainMapping.setActualHost(resource.getProperty(ACTUAL_HOST));
                return domainMapping;
            }
        } catch (RegistryException e) {
            log.info("Error while getting registry resource");
            throw new RuntimeException(e);
View Full Code Here

        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);
View Full Code Here

TOP

Related Classes of org.apache.stratos.lb.common.util.DomainMapping

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.