Search in sources :

Example 1 with CubridCMConfConfig

use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method loadData.

/**
	 * load edit data
	 */
public void loadData() {
    if (editorInput.getTaskCountValue() == 0) {
        return;
    }
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getSite().getShell());
        progress.setCancelable(false);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.unifyHostConfigEditorLoadingDataMsg, editorInput.getTaskCountValue());
                unifyHostConfigUtil = new UnifyHostConfigUtil();
                for (CubridServer cubridServer : editorInput.getCubridServers()) {
                    if (editorInput.isEditCubridConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cubrid.conf", cubridServer.getName()));
                        GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(cubridServer.getServerInfo());
                        getCubridConfParameterTask.execute();
                        if (getCubridConfParameterTask.isSuccess()) {
                            List<String> contentsList = getCubridConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            CubridConfConfig cubridConfConfig = unifyHostConfigUtil.parseStringLineToCubridConfConfig(contentBuilder.toString());
                            cubridConfConfigDataMap.put(cubridServer.getName(), cubridConfConfig);
                            monitor.worked(1);
                        }
                    }
                    if (editorInput.isEditBrokerConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "broker", cubridServer.getName()));
                        GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(cubridServer.getServerInfo());
                        getBrokerConfParameterTask.execute();
                        if (getBrokerConfParameterTask.isSuccess()) {
                            List<String> contentsList = getBrokerConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            BrokerConfig cubridBrokerConfig = cubridBrokerConfUtil.parseStringLineToBrokerConfig(contentBuilder.toString());
                            cubridBrokerConfigDataMap.put(cubridServer.getName(), cubridBrokerConfig);
                            monitor.worked(1);
                        }
                    }
                    if (editorInput.isEditCMConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cm.conf", cubridServer.getName()));
                        GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(cubridServer.getServerInfo());
                        getCMConfParameterTask.execute();
                        if (getCMConfParameterTask.isSuccess()) {
                            List<String> contentsList = getCMConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            CubridCMConfConfig cubridCMConfConfig = unifyHostConfigUtil.parseStringLineToCubridCMConfConfig(contentBuilder.toString());
                            cubridConfCMConfigDataMap.put(cubridServer.getName(), cubridCMConfConfig);
                        //								System.out.println(contentBuilder.toString());
                        }
                        monitor.worked(1);
                    }
                    if (editorInput.isEditHAConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cubrid_ha.conf", cubridServer.getName()));
                        monitor.worked(1);
                    }
                    if (editorInput.isEditACLConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "acl", cubridServer.getName()));
                        monitor.worked(1);
                    }
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) UnifyHostConfigUtil(com.cubrid.cubridmanager.ui.spi.util.UnifyHostConfigUtil) InvocationTargetException(java.lang.reflect.InvocationTargetException) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) List(java.util.List) ArrayList(java.util.ArrayList) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig)

Example 2 with CubridCMConfConfig

use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method saveCubridCMConf.

/**
	 * save cubrid broker conf
	 * @param monitor
	 * @param brokerConfMap
	 * @param editorInput
	 * @return failed server
	 */
public List<String> saveCubridCMConf(IProgressMonitor monitor, LinkedHashMap<String, CubridCMConfConfig> cubridCMConfMap, CubridServer[] cubridServers) {
    List<String> failedServer = new ArrayList<String>();
    for (Entry<String, CubridCMConfConfig> entry : cubridCMConfMap.entrySet()) {
        CubridCMConfConfig cubridCMConfConfig = entry.getValue();
        String serverName = entry.getKey();
        String contents = parseCubridCMConfConfigToDocumnetString(cubridCMConfConfig);
        CubridServer cubridServer = getCubridServer(serverName, cubridServers);
        if (cubridServer != null) {
            monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorSavingDataMsg2, "cm.conf", serverName));
            String[] lines = contents.split(System.getProperty("line.separator"));
            SetCMConfParameterTask task = new SetCMConfParameterTask(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 : SetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCMConfParameterTask) ArrayList(java.util.ArrayList) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 3 with CubridCMConfConfig

use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseStringLineToCubridCMConfConfig.

/**
	 * parseStringLineToCubridCMConfConfig
	 * @param content
	 * @return
	 * @throws Exception
	 */
public CubridCMConfConfig parseStringLineToCubridCMConfConfig(String content) {
    CubridCMConfConfig config = new CubridCMConfConfig();
    String annotationRegex = "#((\\s*).+)|.+";
    Pattern annotationPattern = Pattern.compile(annotationRegex);
    String propertyRegex = ".+=.+";
    Pattern propertyPattern = Pattern.compile(propertyRegex);
    StringBuilder annotationBuilder = new StringBuilder();
    String[] contentArray = content.split(StringUtil.NEWLINE);
    for (String lineString : contentArray) {
        Matcher propertyMatcher = propertyPattern.matcher(lineString);
        Matcher annotationMatcher = annotationPattern.matcher(lineString);
        if (propertyMatcher.find()) {
            //find key and value
            if (lineString.startsWith("#")) {
                if (annotationBuilder == null) {
                    annotationBuilder = new StringBuilder();
                }
                annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
                continue;
            }
            String[] keyValueString = lineString.split("=");
            if (keyValueString.length == 2) {
                String key = keyValueString[0].trim();
                String value = keyValueString[1].trim();
                //new property then set parameter
                CubridCMConfProperty property = new CubridCMConfProperty();
                property.setCubridCMConfPropKey(key);
                property.setCubridCMConfPropValue(value);
                if (annotationBuilder != null) {
                    property.setCubridCMConfPropAnnotation((annotationBuilder.toString()));
                }
                config.addCubridCMConfProperty(property);
                annotationBuilder = null;
            }
        } else if (annotationMatcher.find() || lineString.equals("")) {
            //find annotation
            if (annotationBuilder == null) {
                annotationBuilder = new StringBuilder();
            }
            annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
        }
    }
    return config;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CubridCMConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig)

Example 4 with CubridCMConfConfig

use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCubridCMConfConfigToCommonTableValue.

/**
	 * parse cubrid cm conf data to table value
	 * @param Map<String, CubridConfConfig> cubridConfConfigDataMap
	 */
public List<Map<String, String>> parseCubridCMConfConfigToCommonTableValue(Map<String, CubridCMConfConfig> cubridCMConfConfigDataMap) {
    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>();
    //first row as server name
    result.add(serverMap);
    serverMap.put("0", UnifyHostConfigEditor.SERVERNAMECOLUMNTITLE);
    int index = 1;
    for (String serverName : cubridCMConfConfigDataMap.keySet()) {
        //server name
        serverMap.put("" + (index++), serverName);
    }
    for (Entry<String, CubridCMConfConfig> entry : cubridCMConfConfigDataMap.entrySet()) {
        String serverName = entry.getKey();
        CubridCMConfConfig cubridCMConfConfig = entry.getValue();
        for (CubridCMConfProperty cubridCMConfProperty : cubridCMConfConfig.getPropertyList()) {
            String properKey = cubridCMConfProperty.getCubridCMConfPropKey();
            if (!propList.contains(properKey)) {
                //a new property
                propList.add(properKey);
                dataMap = new HashMap<String, String>();
                result.add(dataMap);
                if (cubridCMConfProperty.getCubridCMConfPropValue() != null) {
                    dataMap.put("0", cubridCMConfProperty.getCubridCMConfPropKey());
                }
                String indexString = getMapKeyByValue(serverMap, serverName);
                if (indexString != null) {
                    dataMap.put(indexString, cubridCMConfProperty.getCubridCMConfPropValue());
                    if (cubridCMConfProperty.getCubridCMConfPropAnnotation() != null) {
                        dataMap.put(indexString + UnifyHostConfigEditor.ANNOTATION, cubridCMConfProperty.getCubridCMConfPropAnnotation());
                    }
                }
            } else {
                Map<String, String> oneRowData = getRowData(result, properKey);
                String indexString = getMapKeyByValue(serverMap, serverName);
                String value = cubridCMConfProperty.getCubridCMConfPropValue();
                String annotation = cubridCMConfProperty.getCubridCMConfPropAnnotation();
                if (oneRowData != null && indexString != null && value != null) {
                    oneRowData.put(indexString, value);
                    if (annotation != null) {
                        oneRowData.put(indexString + UnifyHostConfigEditor.ANNOTATION, annotation);
                    }
                }
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CubridCMConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with CubridCMConfConfig

use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCommonTableValueToCubridCMConfConfig.

/**
	 * parse common table value to cubrid config model list
	 * @param dataList
	 * @return
	 */
public LinkedHashMap<String, CubridCMConfConfig> parseCommonTableValueToCubridCMConfConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    LinkedHashMap<String, CubridCMConfConfig> cubridCMConfConfigMap = new LinkedHashMap<String, CubridCMConfConfig>();
    Map<String, String> serverNameMap = 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 (cubridCMConfConfigMap.get(serverName) == null) {
                    CubridCMConfConfig config = new CubridCMConfConfig();
                    cubridCMConfConfigMap.put(serverName, config);
                }
            }
        } 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 serverName = serverNameMap.get(j + "");
                    CubridCMConfConfig cubridCMConfConfig = cubridCMConfConfigMap.get(serverName);
                    CubridCMConfProperty cubridCMConfProperty = new CubridCMConfProperty();
                    cubridCMConfConfig.addCubridCMConfProperty(cubridCMConfProperty);
                    cubridCMConfProperty.setCubridCMConfPropKey(propName);
                    cubridCMConfProperty.setCubridCMConfPropValue(propValue);
                    String annotation = valueMap.get(Integer.toString(j) + UnifyHostConfigEditor.ANNOTATION);
                    cubridCMConfProperty.setCubridCMConfPropAnnotation(annotation);
                }
            }
        }
    }
    return cubridCMConfConfigMap;
}
Also used : CubridCMConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CubridCMConfConfig (com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig)5 CubridCMConfProperty (com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty)3 ArrayList (java.util.ArrayList)3 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)2 LinkedHashMap (java.util.LinkedHashMap)2 BrokerConfig (com.cubrid.common.ui.spi.model.BrokerConfig)1 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)1 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)1 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)1 SetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.SetCMConfParameterTask)1 CubridConfConfig (com.cubrid.cubridmanager.ui.host.model.CubridConfConfig)1 UnifyHostConfigUtil (com.cubrid.cubridmanager.ui.spi.util.UnifyHostConfigUtil)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1