Examples of LoadbalancerReader


Examples of org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader

     * Visit reader class
     */
    @Override
    public void visit(BaseReader br) throws Exception {
        // FIXME, make as assert here about no class cast exception
        LoadbalancerReader lbRdr = (LoadbalancerReader) br;


        PropertyReader[] pRdrs = lbRdr.getProperties();

        if ((pRdrs != null) && (pRdrs.length > 0)) {
            Property[] props = new Property[pRdrs.length];
            for (int i = 0; i < pRdrs.length; i++) {
                props[i] = new Property();
                pRdrs[i].accept(new PropertyVisitor(props[i]));
            }
            _lb.setProperty2(props);
        }

        ClusterReader[] cRdrs = lbRdr.getClusters();

        if ((cRdrs != null) && (cRdrs.length > 0)) {
            Cluster[] cls = new Cluster[cRdrs.length];
            for (int i = 0; i < cRdrs.length; i++) {
                cls[i] = new Cluster();
View Full Code Here

Examples of org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader

    public void publish(ConnectionManager _connectionManager, Domain domain, String lbConfigName) throws IOException,
            Exception {


        // check if the lb exists
        LoadbalancerReader lbr = LbConfigHelper.getLbReader(domain, appRegistry, lbConfigName);

        HttpURLConnection conn =
                _connectionManager.getConnection(LB_UPDATE_CONTEXT_ROOT);
        OutputStream out = null;
        try {
            conn.setDoOutput(true);
            conn.setRequestMethod(POST);
            conn.connect();
            out = conn.getOutputStream();
            LbConfigHelper.exportXml(lbr, out);
            out.flush();
            lbr.getLbConfig().setLastApplied();
        } catch (UnknownHostException uhe) {
            throw new IOException(LbLogUtil.getStringManager().getString("CannotConnectToLBHost", uhe.getMessage()), uhe);
        } catch (Exception e) {
            throw new IOException(e.getMessage(), e);
        } finally {
View Full Code Here

Examples of org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader

    public void publish(ConnectionManager _connectionManager, Domain domain, String lbConfigName) throws IOException,
            Exception {


        // check if the lb exists
        LoadbalancerReader lbr = LbConfigHelper.getLbReader(domain, appRegistry, lbConfigName);

        HttpURLConnection conn =
                _connectionManager.getConnection(LB_UPDATE_CONTEXT_ROOT);
        OutputStream out = null;
        try {
            conn.setDoOutput(true);
            conn.setRequestMethod(POST);
            conn.connect();
            out = conn.getOutputStream();
            LbConfigHelper.exportXml(lbr, out);
            out.flush();
            lbr.getLbConfig().setLastApplied();
        } catch (UnknownHostException uhe) {
            throw new IOException(LbLogUtil.getStringManager().getString("CannotConnectToLBHost", uhe.getMessage()), uhe);
        } catch (Exception e) {
            throw new IOException(e.getMessage(), e);
        } finally {
View Full Code Here

Examples of org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader

        }
    }

    public String process(AdminCommandContext context) throws Exception {

        LoadbalancerReader lbr = null;
        if (lbName != null && lbConfigName == null && target == null) {
            LoadBalancer lb = LbConfigHelper.getLoadBalancer(domain, lbName);
            lbr = LbConfigHelper.getLbReader(domain, appRegistry, lb.getLbConfigName());
        } else if (lbConfigName != null && lbName == null && target == null) {
            lbr = LbConfigHelper.getLbReader(domain, appRegistry, lbConfigName);
        } else if (target != null && lbName == null && lbConfigName == null) {
            Set<String> clusters = new HashSet<String>();
            clusters.addAll(target);
            lbr = new LoadbalancerReaderImpl(domain, appRegistry, clusters, properties);
        } else {
            String msg = LbLogUtil.getStringManager().getString("ExportHttpLbConfigInvalidArgs");
            throw new Exception(msg);
        }

        if (fileName == null) {
            String configName = lbr.getName();
            if (configName != null) {
                fileName = DEFAULT_LB_XML_FILE_NAME + "." + configName;
            } else {
                fileName = DEFAULT_LB_XML_FILE_NAME;
            }
        }

        File lbConfigFile = new File(fileName);
        if (!lbConfigFile.isAbsolute() && !retrieveFile) {
            File loadbalancerDir = new File(env.getInstanceRoot(),
                    "load-balancer");
            if (!loadbalancerDir.exists()) {
                loadbalancerDir.mkdir();
            }
            lbConfigFile = new File(loadbalancerDir, fileName);
        }

        if (type !=null){
            if(!(type.equals("otd") || type.equals("apache"))){
                String msg = LbLogUtil.getStringManager().getString(
                        "InvalidType");
                throw new Exception(msg);
            }
            File tmpLbWorkerFile = null;
            if (retrieveFile) {
                if (type.equals("apache")) {
                    tmpLbWorkerFile = File.createTempFile("worker", ".properties");
                } else {
                    tmpLbWorkerFile = File.createTempFile("otd", ".properties");
                }
                tmpLbWorkerFile.deleteOnExit();
            } else {
                if (lbConfigFile.exists()) {
                    String msg = LbLogUtil.getStringManager().getString(
                            "FileExists", lbConfigFile.getPath());
                    throw new Exception(msg);
                }

                if (!(lbConfigFile.getParentFile().exists())) {
                    String msg = LbLogUtil.getStringManager().getString(
                            "ParentFileMissing", lbConfigFile.getParent());
                    throw new Exception(msg);
                }
                tmpLbWorkerFile = lbConfigFile;
            }

            FileOutputStream fo = null;

            try {
                fo = new FileOutputStream(tmpLbWorkerFile);
                if (type.equals("apache")) {
                    LbConfigHelper.exportWorkerProperties(lbr, fo);
                } else {
                    LbConfigHelper.exportOtdProperties(lbr, fo);
                }
                if (retrieveFile) {
                    retrieveLbConfig(context, lbConfigFile, tmpLbWorkerFile);
                }
                LbConfig lbConfig = lbr.getLbConfig();
    //Check for the case when lbtargets are provided
                //In such a case, lbconfig will be null
    if(lbConfig != null){
                    lbConfig.setLastExported();
    }
                String msg = LbLogUtil.getStringManager().getString(
                        "GeneratedFileLocation", lbConfigFile.toString());
                return msg;
            } finally {
                if (fo != null) {
                    fo.close();
                    fo = null;
                }
            }
        } else {

            File tmpLbXmlFile = null;
            if (retrieveFile) {
                tmpLbXmlFile = File.createTempFile("load-balancer", ".xml");
                tmpLbXmlFile.deleteOnExit();
            } else {
                if (lbConfigFile.exists()) {
                    String msg = LbLogUtil.getStringManager().getString(
                            "FileExists", lbConfigFile.getPath());
                    throw new Exception(msg);
                }

                if (!(lbConfigFile.getParentFile().exists())) {
                    String msg = LbLogUtil.getStringManager().getString(
                            "ParentFileMissing", lbConfigFile.getParent());
                    throw new Exception(msg);
                }
                tmpLbXmlFile = lbConfigFile;
            }

            FileOutputStream fo = null;

            try {
                fo = new FileOutputStream(tmpLbXmlFile);
                LbConfigHelper.exportXml(lbr, fo);
                if (retrieveFile) {
                    retrieveLbConfig(context, lbConfigFile, tmpLbXmlFile);
                }
                LbConfig lbConfig = lbr.getLbConfig();
                //Check for the case when lbtargets are provided
                //In such a case, lbconfig will be null
                if(lbConfig != null){
                    lbConfig.setLastExported();
                }
View Full Code Here

Examples of org.jvnet.glassfish.comms.admin.clbadmin.reader.api.LoadbalancerReader

        } else {
            filePath = newConfigFileName;
        }

        // check if the lb exists
        LoadbalancerReader lbr = getLbReader(_ctx, _name);
        FileOutputStream out = null;

        try {
            out = new FileOutputStream(filePath);

            // tranform the data using visitor pattern
            Loadbalancer _lb = new Loadbalancer();

            LoadbalancerVisitor lbVstr = new LoadbalancerVisitor(_lb);
            lbr.accept(lbVstr);

            ObjectFactory clbFactory = new ObjectFactory();
            clbFactory.store(_lb, out);
            out.flush();
            if (!ClbAdminEventHelper.isClbDebug())
View Full Code Here

Examples of org.jvnet.glassfish.comms.admin.clbadmin.reader.api.LoadbalancerReader

    }
   
    public String getClbXML() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            LoadbalancerReader lbr = _clbp.getLbReader(_ctx, _name);
            // tranform the data using visitor pattern
            Loadbalancer _lb = new Loadbalancer();
            LoadbalancerVisitor lbVstr = new LoadbalancerVisitor(_lb);
            lbr.accept(lbVstr);
            ObjectFactory clbFactory = new ObjectFactory();
            clbFactory.store(_lb, baos);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
View Full Code Here

Examples of org.jvnet.glassfish.comms.admin.clbadmin.reader.api.LoadbalancerReader

    /**
     * Visit reader class
     */
    public void visit(BaseReader br) {
        // FIXME, make as assert here about no class cast exception
        LoadbalancerReader lbRdr = (LoadbalancerReader) br;

        try {
            _lb.setHttpPolicy(lbRdr.getHttpPolicy());
            _lb.setSipPolicy(lbRdr.getSipPolicy());
            _lb.setDcrFile(lbRdr.getDcrFile());
        } catch (LbReaderException le) {
            // XXX ignore
        }

        Property prop = null;
        PropertyReader[] pRdrs = null;

        try {
            pRdrs = lbRdr.getProperties();
        } catch (LbReaderException le) {
            // should we throw this exception XXX ???
            // or fill in with default values
        }

        if ((pRdrs != null) && (pRdrs.length > 0)) {
            for (int i = 0; i < pRdrs.length; i++) {
                prop = new Property();
                pRdrs[i].accept(new PropertyVisitor(prop));
                _lb.getProperty().add(prop);
            }
        }

        ClusterReader[] cRdrs = null;

        try {
            cRdrs = lbRdr.getClusters();
        } catch (LbReaderException le) {
            // should we throw this exception XXX ???
            // or fill in with default values
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.