Package org.glassfish.loadbalancer.admin.cli.reader.api

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()) {
                boolean isMkdirSuccess = loadbalancerDir.mkdir();
                if(!isMkdirSuccess){
                  String msg = LbLogUtil.getStringManager().getString(
                            "directoryCreationFailed");
                    throw new Exception(msg);
                }
            }
            lbConfigFile = new File(loadbalancerDir, fileName);
        }

            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


    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

     */
    @Override
    public void visit(BaseReader br) throws Exception {
        // FIXME, make as assert here about no class cast exception
    if (br instanceof LoadbalancerReader) {
      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

        }
    }

    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 lbXmlFile = new File(fileName);
        if(!lbXmlFile.isAbsolute() && !retrieveFile){
            File loadbalancerDir = new File(env.getInstanceRoot(),
                    "load-balancer");
            if(!loadbalancerDir.exists()){
                loadbalancerDir.mkdir();
            }
            lbXmlFile = new File(loadbalancerDir, fileName);
        }

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

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

        FileOutputStream fo = null;

        try {
            fo = new FileOutputStream(tmpLbXmlFile);
            LbConfigHelper.exportXml(lbr, fo);
            if(retrieveFile){
                retrieveLbXml(context, lbXmlFile, tmpLbXmlFile);
            }
            lbr.getLbConfig().setLastExported();
            String msg = LbLogUtil.getStringManager().getString(
                    "GeneratedFileLocation", lbXmlFile.toString());
            return msg;
        } finally {
            if (fo != null) {
View Full Code Here

    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

        }
    }

    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 lbXmlFile = new File(fileName);
        if(!lbXmlFile.isAbsolute() && !retrieveFile){
            File loadbalancerDir = new File(env.getInstanceRoot(),
                    "load-balancer");
            if(!loadbalancerDir.exists()){
                loadbalancerDir.mkdir();
            }
            lbXmlFile = new File(loadbalancerDir, fileName);
        }

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

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

        FileOutputStream fo = null;

        try {
            fo = new FileOutputStream(tmpLbXmlFile);
            LbConfigHelper.exportXml(lbr, fo);
            if(retrieveFile){
                retrieveLbXml(context, lbXmlFile, 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

     * 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

    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

    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

        }
    }

    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

TOP

Related Classes of org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader

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.