Search in sources :

Example 1 with CubridShardFolder

use of com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder in project cubrid-manager by CUBRID.

the class NavigatorTreeLabelProvider method getImage.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
	 */
public Image getImage(Object element) {
    String iconPath = "";
    if (element instanceof CubridServer) {
        CubridServer server = (CubridServer) element;
        if (server.isConnected()) {
            iconPath = server.getConnectedIconPath();
        } else {
            iconPath = server.getDisConnectedIconPath();
        }
        Image serverImage = CubridManagerUIPlugin.getImage(iconPath);
        return decorateServerImgae(serverImage, server);
    } else if (element instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) element;
        if (database.getRunningType() == DbRunningType.STANDALONE && database.isLogined()) {
            iconPath = database.getStopAndLoginIconPath();
        } else if (database.getRunningType() == DbRunningType.STANDALONE && !database.isLogined()) {
            iconPath = database.getStopAndLogoutIconPath();
        } else if (database.getRunningType() == DbRunningType.CS && database.isLogined()) {
            iconPath = database.getStartAndLoginIconPath();
        } else if (database.getRunningType() == DbRunningType.CS && !database.isLogined()) {
            iconPath = database.getStartAndLogoutIconPath();
        }
        Image databaseImage = CubridManagerUIPlugin.getImage(iconPath);
        return decorateDatabaseImgae(databaseImage, database);
    } else if (element instanceof CubridBrokerFolder) {
        CubridBrokerFolder brokerFolder = (CubridBrokerFolder) element;
        if (brokerFolder.isRunning()) {
            iconPath = brokerFolder.getStartedIconPath();
        } else {
            iconPath = brokerFolder.getStopedIconPath();
        }
    } else if (element instanceof CubridBroker) {
        CubridBroker broker = (CubridBroker) element;
        if (broker.isRunning()) {
            iconPath = broker.getStartedIconPath();
        } else {
            iconPath = broker.getStopedIconPath();
        }
    } else if (element instanceof CubridShardFolder) {
        // TODO shard
        CubridShardFolder shardFolder = (CubridShardFolder) element;
        // if (shardFolder.isEnable()) {
        if (shardFolder.isRunning()) {
            iconPath = shardFolder.getStartedIconPath();
        } else {
            iconPath = shardFolder.getStopedIconPath();
        }
    // } else {
    // iconPath = shardFolder.getDisableIconPath();
    // }
    } else if (element instanceof CubridShard) {
        CubridShard shard = (CubridShard) element;
        if (shard.isRunning()) {
            iconPath = shard.getStartedIconPath();
        } else {
            iconPath = shard.getStopedIconPath();
        }
    } else if (element instanceof ICubridNode) {
        ICubridNode node = (ICubridNode) element;
        iconPath = node.getIconPath();
    }
    if (iconPath != null && iconPath.length() > 0) {
        return CubridManagerUIPlugin.getImage(iconPath.trim());
    }
    return super.getImage(element);
}
Also used : CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) CubridBroker(com.cubrid.cubridmanager.ui.spi.model.CubridBroker) CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) StyledString(org.eclipse.jface.viewers.StyledString) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) Image(org.eclipse.swt.graphics.Image) DecoratedImage(com.cubrid.common.ui.decorator.DecoratedImage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CubridBrokerFolder(com.cubrid.cubridmanager.ui.spi.model.CubridBrokerFolder)

Example 2 with CubridShardFolder

use of com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder in project cubrid-manager by CUBRID.

the class StartShardEnvAction method run.

/**
	 * Override the run method in order to complete starting broker environment
	 * 
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    CubridShardFolder selection = (CubridShardFolder) obj[0];
    if (null == selection) {
        return;
    }
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    StartShardTask task = new StartShardTask(serverInfo, null);
    IMessageHandler messageHandler = new IMessageHandler() {

        public String translate(String message) {
            if (message == null) {
                return "";
            }
            if (message.indexOf("failed to metadata validate check") != -1) {
                return Messages.errStartShardNotConfigOrFailed + StringUtil.NEWLINE + StringUtil.NEWLINE + Messages.msgShardGuide;
            }
            return "";
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.startShardEnvActionName, messageHandler);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    if (!task.isSuccess()) {
        String msg = Messages.bind(Messages.errCanNotStartShardBroker, Messages.msgShardGuide);
        CommonUITool.openErrorBox(msg);
        return;
    }
    selection.setRunning(true);
    TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
    CommonUITool.refreshNavigatorTree(treeViewer, selection);
    ActionManager.getInstance().fireSelectionChanged(getSelection());
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IMessageHandler(com.cubrid.common.ui.spi.IMessageHandler) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) StartShardTask(com.cubrid.cubridmanager.core.shard.task.StartShardTask)

Example 3 with CubridShardFolder

use of com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder in project cubrid-manager by CUBRID.

the class StartShardEnvAction method isSupportedNode.

/**
	 * Return whether this action support this object,if not support,this action
	 * will be disabled
	 * 
	 * @param obj
	 *            the object
	 * @return <code>true</code> if supported;<code>false</code>
	 */
public static boolean isSupportedNode(Object obj) {
    if (obj instanceof CubridShardFolder) {
        CubridShardFolder selection = ((CubridShardFolder) obj);
        if (!selection.isEnable()) {
            return false;
        }
        ServerUserInfo userInfo = selection.getServer().getServerInfo().getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_ADMIN != userInfo.getCasAuth()) {
            return false;
        }
        return !selection.isRunning();
    }
    return false;
}
Also used : CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 4 with CubridShardFolder

use of com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder in project cubrid-manager by CUBRID.

the class ShardEnvStatusView method nodeChanged.

/**
	 * Response to cubrid node changes
	 * 
	 * @param event
	 *            the event
	 */
public void nodeChanged(CubridNodeChangedEvent event) {
    ICubridNode eventNode = event.getCubridNode();
    if (eventNode == null || this.cubridNode == null) {
        return;
    }
    // if it is not in the same host,return
    if (!eventNode.getServer().getId().equals(this.cubridNode.getServer().getId())) {
        return;
    }
    // if changed node is not broker folder or server,return
    String type = eventNode.getType();
    if (!CubridNodeType.SHARD_FOLDER.equals(type) && !CubridNodeType.SERVER.equals(type)) {
        return;
    }
    synchronized (this) {
        if (StringUtil.isEqual(type, NodeType.SERVER)) {
            String id = eventNode.getId();
            CubridShardFolder currentNode = (CubridShardFolder) eventNode.getChild(id);
            this.cubridNode = currentNode;
        } else {
            this.cubridNode = eventNode;
        }
        if (this.cubridNode == null || !((CubridShardFolder) eventNode).isRunning()) {
            setRunflag(false);
            this.setTitleImage(CubridManagerUIPlugin.getImage("icons/navigator/broker_group.png"));
            return;
        } else {
            setRunflag(true);
            this.setTitleImage(CubridManagerUIPlugin.getImage("icons/navigator/broker_service_started.png"));
        }
        refresh();
    }
}
Also used : CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 5 with CubridShardFolder

use of com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder in project cubrid-manager by CUBRID.

the class CubridBrokersFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_NONE == userInfo.getCasAuth()) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        BrokerInfos brokerInfos = new BrokerInfos();
        final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        brokerInfos = task.getResultModel();
        List<ICubridNode> oldNodeList = parent.getChildren();
        parent.removeAllChild();
        List<BrokerInfo> brokerInfoList = (brokerInfos == null || brokerInfos.getBorkerInfoList() == null) ? null : brokerInfos.getBorkerInfoList().getBrokerInfoList();
        for (int i = 0; brokerInfoList != null && i < brokerInfoList.size(); i++) {
            BrokerInfo brokerInfo = brokerInfoList.get(i);
            String id = parent.getId() + NODE_SEPARATOR + brokerInfo.getName();
            ICubridNode brokerInfoNode = isContained(oldNodeList, id);
            if (brokerInfoNode == null) {
                brokerInfoNode = new CubridBroker(id, brokerInfo.getName(), "icons/navigator/broker.png");
                ((CubridBroker) brokerInfoNode).setStartedIconPath("icons/navigator/broker_started.png");
                brokerInfoNode.setType(CubridNodeType.BROKER);
                brokerInfoNode.setContainer(true);
                brokerInfoNode.setModelObj(brokerInfo);
                brokerInfoNode.setViewId(BrokerStatusView.ID);
                brokerInfoNode.setLoader(new CubridBrokerFolderLoader());
            } else {
                brokerInfoNode.setModelObj(brokerInfo);
                if (brokerInfoNode.getLoader() != null && brokerInfoNode.getLoader().isLoaded()) {
                    brokerInfoNode.getLoader().setLoaded(false);
                    brokerInfoNode.getChildren(monitor);
                }
            }
            parent.addChild(brokerInfoNode);
        }
        serverInfo.setBrokerInfos(brokerInfos);
        // For the Shard Broker Folder
        if (CompatibleUtil.isSupportShard(serverInfo)) {
            Shards shards = new Shards();
            GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
            getShardConfTask.execute();
            // !"File(?) open error".equals(errorMsg.trim())) {
            if (getShardConfTask.isSuccess()) {
                GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
                getShardStatusTask.execute();
                boolean runningShard = getShardStatusTask.isSuccess();
                serverInfo.setShards(shards);
                shards.setRunning(runningShard);
                String shardFolderId = parent.getId() + NODE_SEPARATOR + SHARD_FOLDER_ID;
                ICubridNode shardFolder = parent.getChild(shardFolderId);
                if (shardFolder == null) {
                    shardFolder = new CubridShardFolder(shardFolderId, SHARD_FOLDER_NAME);
                    ICubridNodeLoader loader = new CubridShardsFolderLoader((CubridShardFolder) shardFolder);
                    loader.setLevel(getLevel());
                    shardFolder.setLoader(loader);
                    parent.addChild(shardFolder);
                // shardFolder.getChildren(monitor);
                } else {
                    if (shardFolder.getLoader() != null && shardFolder.getLoader().isLoaded()) {
                        shardFolder.getLoader().setLoaded(false);
                        shardFolder.getChildren(monitor);
                    }
                }
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CubridBroker(com.cubrid.cubridmanager.ui.spi.model.CubridBroker) CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

CubridShardFolder (com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder)9 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)4 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)3 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2 CubridBroker (com.cubrid.cubridmanager.ui.spi.model.CubridBroker)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 DecoratedImage (com.cubrid.common.ui.decorator.DecoratedImage)1 IMessageHandler (com.cubrid.common.ui.spi.IMessageHandler)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)1 BrokerInfo (com.cubrid.cubridmanager.core.broker.model.BrokerInfo)1 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)1 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)1 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)1 GetShardConfTask (com.cubrid.cubridmanager.core.shard.task.GetShardConfTask)1