Search in sources :

Example 6 with BrokerConfig

use of com.cubrid.common.ui.spi.model.BrokerConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method saveBrokerConf.

/**
	 * save cubrid broker conf
	 * @param monitor
	 * @param brokerConfMap
	 * @param editorInput
	 * @return failed server
	 */
public List<String> saveBrokerConf(IProgressMonitor monitor, LinkedHashMap<String, BrokerConfig> brokerConfMap, CubridServer[] cubridServers) {
    List<String> failedServer = new ArrayList<String>();
    BrokerConfPersistUtil cubridBrokerConfUtil = new BrokerConfPersistUtil();
    for (Entry<String, BrokerConfig> entry : brokerConfMap.entrySet()) {
        BrokerConfig cubridBrokerConfig = entry.getValue();
        String serverName = entry.getKey();
        String contents = cubridBrokerConfUtil.readBrokerConfig(cubridBrokerConfig);
        CubridServer cubridServer = getCubridServer(serverName, cubridServers);
        if (cubridServer != null) {
            monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorSavingDataMsg2, "broker.conf", serverName));
            String[] lines = contents.split(System.getProperty("line.separator"));
            SetBrokerConfParameterTask task = new SetBrokerConfParameterTask(cubridServer.getServerInfo());
            task.setConfContents(Arrays.asList(lines));
            task.execute();
            if (!task.isSuccess()) {
                failedServer.add(cubridServer.getName());
            }
            task.finish();
            monitor.worked(1);
        }
    }
    return failedServer;
}
Also used : BrokerConfPersistUtil(com.cubrid.common.ui.spi.persist.BrokerConfPersistUtil) BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) ArrayList(java.util.ArrayList) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) SetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.SetBrokerConfParameterTask)

Example 7 with BrokerConfig

use of com.cubrid.common.ui.spi.model.BrokerConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCommonTableValueToCubridBrokerConfig.

/**
	 * parse common table value to broker config model list
	 * @param dataList
	 * @return
	 */
public LinkedHashMap<String, BrokerConfig> parseCommonTableValueToCubridBrokerConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    LinkedHashMap<String, BrokerConfig> cubridBrokerConfigMap = new LinkedHashMap<String, BrokerConfig>();
    Map<String, String> serverNameMap = null;
    Map<String, String> brokerNameMap = null;
    for (int i = 0; i < dataList.size(); i++) {
        if (i == 0) {
            //first data is server name
            serverNameMap = dataList.get(i);
            for (int j = 1; j < serverNameMap.size(); j++) {
                String serverName = serverNameMap.get(j + "");
                if (serverName == null || "".equals(serverName)) {
                    continue;
                }
                if (cubridBrokerConfigMap.get(serverName) == null) {
                    BrokerConfig config = new BrokerConfig();
                    cubridBrokerConfigMap.put(serverName, config);
                }
            }
        } else if (i == 1) {
            //second data is server name
            brokerNameMap = dataList.get(i);
            for (int j = 1; j < brokerNameMap.size(); j++) {
                String brokerName = brokerNameMap.get(j + "");
                if (brokerName == null || "".equals(brokerName)) {
                    continue;
                }
                String annotation = brokerNameMap.get(j + UnifyHostConfigEditor.ANNOTATION);
                CubridBrokerProperty brokerConf = new CubridBrokerProperty();
                brokerConf.setCubridBrokerPropKey(brokerName);
                brokerConf.setCubridBrokerPropAnnotation(annotation);
                brokerConf.setCubridBroker(true);
                String serverName = serverNameMap.get(j + "");
                BrokerConfig config = cubridBrokerConfigMap.get(serverName);
                config.addCubridBrokerProperty(brokerConf);
            }
        } else {
            Map<String, String> valueMap = dataList.get(i);
            String propName = "";
            String propValue = "";
            for (int j = 0; j < tableColumnCount; j++) {
                String value = valueMap.get(Integer.toString(j));
                if (j == 0) {
                    propName = value;
                    continue;
                }
                propValue = value;
                if (propValue != null && !"".equals(propValue)) {
                    String brokerName = brokerNameMap.get(j + "");
                    String serverName = serverNameMap.get(j + "");
                    BrokerConfig config = cubridBrokerConfigMap.get(serverName);
                    CubridBrokerProperty brokerConf = getCubridBrokerPropertyByBrokerName(config, brokerName);
                    if (brokerConf != null) {
                        CubridBrokerProperty brokerProp = new CubridBrokerProperty();
                        brokerConf.addCubridBrokerProperty(brokerProp);
                        brokerProp.setCubridBrokerPropKey(propName);
                        brokerProp.setCubridBrokerPropValue(propValue);
                        String annotation = valueMap.get(Integer.toString(j) + UnifyHostConfigEditor.ANNOTATION);
                        brokerProp.setCubridBrokerPropAnnotation(annotation);
                    }
                }
            }
        }
    }
    return cubridBrokerConfigMap;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with BrokerConfig

use of com.cubrid.common.ui.spi.model.BrokerConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCubridBrokerConfigToCommonTableValue.

/**
	 * parse broker data to table value
	 * @param Map<String, CubridConfConfig> cubridBrokerConfigDataMap
	 */
public List<Map<String, String>> parseCubridBrokerConfigToCommonTableValue(Map<String, BrokerConfig> cubridBrokerConfigDataMap) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    //mark property in the list
    List<String> propList = new ArrayList<String>();
    Map<String, String> dataMap = null;
    Map<String, String> serverMap = new HashMap<String, String>();
    Map<String, String> brokerMap = new HashMap<String, String>();
    //first row as server name
    result.add(serverMap);
    serverMap.put("0", UnifyHostConfigEditor.SERVERNAMECOLUMNTITLE);
    int index = 1;
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            //server name
            serverMap.put("" + index, entry.getKey());
            if (cubridBroker.getCubridBrokerPropAnnotation() != null) {
                //set annotation
                serverMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridBroker.getCubridBrokerPropAnnotation());
            }
            index++;
        }
    }
    //second row as broker name
    result.add(brokerMap);
    brokerMap.put("0", UnifyHostConfigEditor.BROKERNAMECOLUMNTITLE);
    index = 1;
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            //broker name
            brokerMap.put("" + index, cubridBroker.getCubridBrokerPropKey());
            if (cubridBroker.getCubridBrokerPropAnnotation() != null) {
                //set annotation
                brokerMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridBroker.getCubridBrokerPropAnnotation());
            }
            index++;
        }
    }
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        String serviceName = entry.getKey();
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            String brokerName = cubridBroker.getCubridBrokerPropKey();
            for (CubridBrokerProperty prop : cubridBroker.getPropertyList()) {
                String properKey = prop.getCubridBrokerPropKey();
                if (!propList.contains(properKey)) {
                    //a new property
                    propList.add(properKey);
                    dataMap = new HashMap<String, String>();
                    result.add(dataMap);
                    dataMap.put("0", prop.getCubridBrokerPropKey());
                    if (prop.getCubridBrokerPropValue() != null) {
                        dataMap.put("0", prop.getCubridBrokerPropKey());
                    }
                    String indexString = getMapKeyByValue(serverMap, brokerMap, serviceName, brokerName);
                    if (indexString != null) {
                        dataMap.put(indexString, prop.getCubridBrokerPropValue());
                        if (prop.getCubridBrokerPropAnnotation() != null) {
                            dataMap.put(indexString + UnifyHostConfigEditor.ANNOTATION, prop.getCubridBrokerPropAnnotation());
                        }
                    }
                } else {
                    Map<String, String> oneRowData = getRowData(result, properKey);
                    String indexString = getMapKeyByValue(serverMap, brokerMap, serviceName, brokerName);
                    String value = prop.getCubridBrokerPropValue();
                    String annotation = prop.getCubridBrokerPropAnnotation();
                    if (oneRowData != null && indexString != null && value != null) {
                        oneRowData.put(indexString, value);
                        if (annotation != null) {
                            oneRowData.put(indexString + UnifyHostConfigEditor.ANNOTATION, annotation);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with BrokerConfig

use of com.cubrid.common.ui.spi.model.BrokerConfig in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method parseCommonTableValueToBrokerConfig.

/**
	 * parse common table value to broker config model
	 *
	 * @param dataList
	 * @return
	 */
public BrokerConfig parseCommonTableValueToBrokerConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    BrokerConfig config = new BrokerConfig();
    Map<String, String> brokerNameMap = null;
    for (int i = 0; i < dataList.size(); i++) {
        if (i == 0) {
            //first data is broker name
            brokerNameMap = dataList.get(i);
            for (int j = 1; j < brokerNameMap.size(); j++) {
                String brokerName = brokerNameMap.get(Integer.toString(j));
                if (StringUtil.isEmpty(brokerName)) {
                    continue;
                }
                String annotation = brokerNameMap.get(Integer.toString(j) + ANNOTATION);
                CubridBrokerProperty brokerConf = new CubridBrokerProperty();
                brokerConf.setCubridBrokerPropKey(brokerName);
                brokerConf.setCubridBrokerPropAnnotation(annotation);
                brokerConf.setCubridBroker(true);
                config.addCubridBrokerProperty(brokerConf);
            }
        } else {
            Map<String, String> valueMap = dataList.get(i);
            String propName = "";
            String propValue = "";
            for (int j = 0; j < tableColumnCount; j++) {
                String value = valueMap.get(Integer.toString(j));
                if (j == 0) {
                    propName = value;
                    continue;
                }
                propValue = value;
                if (StringUtil.isNotEmpty(propValue)) {
                    String brokerName = brokerNameMap.get(Integer.toString(j));
                    CubridBrokerProperty brokerConf = getCubridBrokerPropertyByBrokerName(config, brokerName);
                    if (brokerConf != null) {
                        CubridBrokerProperty brokerProp = new CubridBrokerProperty();
                        brokerConf.addCubridBrokerProperty(brokerProp);
                        brokerProp.setCubridBrokerPropKey(propName);
                        brokerProp.setCubridBrokerPropValue(propValue);
                        String annotation = valueMap.get(Integer.toString(j) + ANNOTATION);
                        brokerProp.setCubridBrokerPropAnnotation(annotation);
                    }
                }
            }
        }
    }
    return config;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty)

Example 10 with BrokerConfig

use of com.cubrid.common.ui.spi.model.BrokerConfig in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method parseStringLineToBrokerConfig.

/**
	 * parseStringLineToCubridBrokerConfig
	 *
	 * @param content
	 * @return
	 * @throws Exception
	 */
public BrokerConfig parseStringLineToBrokerConfig(String content) {
    BrokerConfig config = new BrokerConfig();
    String cubridBrokerConfRegex = "\\[.*";
    Pattern cubridBrokerConfPattern = Pattern.compile(cubridBrokerConfRegex);
    String annotationRegex = "#(\\s*).+";
    Pattern annotationPattern = Pattern.compile(annotationRegex);
    String propertyRegex = ".+=.+";
    Pattern propertyPattern = Pattern.compile(propertyRegex);
    CubridBrokerProperty brokerConfProp = null;
    StringBuilder annotationBuilder = new StringBuilder();
    String[] contentArray = content.split(StringUtil.NEWLINE);
    for (String lineString : contentArray) {
        Matcher cubridBrokerConfMatcher = cubridBrokerConfPattern.matcher(lineString);
        Matcher annotationMatcher = annotationPattern.matcher(lineString);
        Matcher propertyMatcher = propertyPattern.matcher(lineString);
        if (cubridBrokerConfMatcher.find()) {
            //find broker like [broker] [%query_editor]
            brokerConfProp = new CubridBrokerProperty();
            brokerConfProp.setCubridBrokerPropKey(lineString);
            brokerConfProp.setCubridBroker(true);
            if (annotationBuilder != null) {
                brokerConfProp.setCubridBrokerPropAnnotation(annotationBuilder.toString());
            }
            config.addCubridBrokerProperty(brokerConfProp);
            annotationBuilder = null;
        } else if (annotationMatcher.find() || lineString.equals("")) {
            //find annotation
            if (annotationBuilder == null) {
                annotationBuilder = new StringBuilder();
            }
            annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
        } else if (propertyMatcher.find()) {
            //find key and value
            if (brokerConfProp == null) {
                //if there is no broker,ignore the property
                continue;
            }
            String[] keyValueString = lineString.split("=");
            if (keyValueString.length == 2) {
                String key = keyValueString[0].trim();
                String value = keyValueString[1].trim();
                //new property then set parameter
                CubridBrokerProperty property = new CubridBrokerProperty();
                property.setCubridBrokerPropKey(key);
                property.setCubridBrokerPropValue(value);
                if (annotationBuilder != null) {
                    property.setCubridBrokerPropAnnotation(annotationBuilder.toString());
                }
                brokerConfProp.addCubridBrokerProperty(property);
                annotationBuilder = null;
            }
        } else {
            // opthers see it to bottom annotation
            if (annotationBuilder != null) {
                annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
            }
        }
    }
    if (annotationBuilder != null) {
        config.setConfAnnotation(annotationBuilder.toString());
    }
    return config;
}
Also used : Pattern(java.util.regex.Pattern) BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) Matcher(java.util.regex.Matcher) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty)

Aggregations

BrokerConfig (com.cubrid.common.ui.spi.model.BrokerConfig)16 PartInitException (org.eclipse.ui.PartInitException)6 CubridBrokerProperty (com.cubrid.common.ui.spi.model.CubridBrokerProperty)5 ArrayList (java.util.ArrayList)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Point (org.eclipse.swt.graphics.Point)3 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)2 File (java.io.File)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 TableItem (org.eclipse.swt.widgets.TableItem)2 ToolBar (org.eclipse.swt.widgets.ToolBar)2 ToolItem (org.eclipse.swt.widgets.ToolItem)2