Search in sources :

Example 1 with CubridShard

use of com.cubrid.cubridmanager.ui.spi.model.CubridShard 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 CubridShard

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

the class StartShardAction method run.

/**
	 * Override the run method in order to complete starting broker environment
	 * 
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    CubridShard selection = (CubridShard) obj[0];
    if (null == selection) {
        return;
    }
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    StartShardTask task = new StartShardTask(serverInfo, selection.getName());
    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.startShardActionName, 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) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) StartShardTask(com.cubrid.cubridmanager.core.shard.task.StartShardTask)

Example 3 with CubridShard

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

the class StartShardAction 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 CubridShard) {
        CubridShard selection = ((CubridShard) obj);
        ServerUserInfo userInfo = selection.getServer().getServerInfo().getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_ADMIN != userInfo.getCasAuth()) {
            return false;
        }
        return !selection.isRunning();
    }
    return false;
}
Also used : CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 4 with CubridShard

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

the class StopShardAction 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 CubridShard) {
        CubridShard selection = ((CubridShard) obj);
        ServerUserInfo userInfo = selection.getServer().getServerInfo().getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_ADMIN != userInfo.getCasAuth()) {
            return false;
        }
        return selection.isRunning();
    }
    return false;
}
Also used : CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 5 with CubridShard

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

the class CubridShardsFolderLoader 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();
        if (serverInfo == null) {
            LOGGER.error("The serverInfo is a null.");
            return;
        }
        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;
        }
        Display display = Display.getDefault();
        boolean statusTag = false;
        boolean confTag = false;
        Shards shards = new Shards();
        GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
        monitorCancel(monitor, new ITask[] { getShardConfTask });
        getShardConfTask.execute();
        if (!monitor.isCanceled() && !getShardConfTask.isSuccess()) {
            final String errorMsg = getShardConfTask.getErrorMsg();
            confTag = false;
            cubridShardFolder.setEnable(false);
            parent.removeAllChild();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
        // return;
        } else {
            confTag = true;
            getShardConfTask.loadDataToModel();
            serverInfo.setShards(shards);
        }
        GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
        monitorCancel(monitor, new ITask[] { getShardStatusTask });
        getShardStatusTask.execute();
        ShardsStatus shardsStatus = null;
        if (getShardStatusTask.isSuccess()) {
            shardsStatus = getShardStatusTask.getShardsStatus();
            cubridShardFolder.setRunning(true);
            statusTag = true;
        } else {
            final String errorMsg = getShardStatusTask.getErrorMsg();
            if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
                statusTag = false;
                if (errorMsg.trim().contains("cubrid shard is not running")) {
                    cubridShardFolder.setRunning(false);
                    parent.removeAllChild();
                // return;
                } else {
                    display.syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openErrorBox(errorMsg);
                        }
                    });
                }
            }
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        List<ICubridNode> oldNodeList = parent.getChildren();
        parent.removeAllChild();
        Map<String, ShardStatus> tmpCache = new HashMap<String, ShardStatus>();
        if (statusTag) {
            List<ShardStatus> shardStatuss = (shardsStatus == null || shardsStatus.getShardStatuss() == null) ? null : shardsStatus.getShardStatuss();
            for (int i = 0; shardStatuss != null && i < shardStatuss.size(); i++) {
                ShardStatus shard = shardStatuss.get(i);
                tmpCache.put(shard.getName(), shard);
            }
        }
        if (confTag) {
            List<Shard> shardList = (shards == null || shards.getShardList() == null) ? null : shards.getShardList();
            for (int i = 0; shardList != null && i < shardList.size(); i++) {
                Shard shard = shardList.get(i);
                //
                ShardConnection shardConnection = new ShardConnection();
                shard.setShardConnectionFile(shardConnection);
                GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
                getShardConnectionConfTask.execute();
                getShardConnectionConfTask.loadDataToModel();
                ShardKeys shardKeys = new ShardKeys();
                shard.setShardKeysFile(shardKeys);
                GetShardConfTask<ShardKeys> getShardKeyConfTask = new GetShardConfTask<ShardKeys>(serverInfo, shardKeys);
                getShardKeyConfTask.execute();
                getShardKeyConfTask.loadDataToModel();
                //
                String id = parent.getId() + NODE_SEPARATOR + shard.getName();
                ICubridNode shardNode = isContained(oldNodeList, id);
                ShardStatus shardStatus = tmpCache.get(shard.getName());
                String shardLabel = shardStatus != null ? " (" + shardStatus.getPort() + "," + shardStatus.getAccessMode() + ")" : "";
                if (shardNode == null) {
                    shardNode = new CubridShard(id, shard.getName() + shardLabel);
                    ((CubridShard) shardNode).setName(shard.getName());
                    shardNode.setType(CubridNodeType.SHARD);
                    shardNode.setContainer(true);
                    shardNode.setModelObj(shard);
                    shardNode.setLoader(new CubridShardFolderLoader());
                } else {
                    shardNode.setModelObj(shard);
                    if (shardNode.getLoader() != null && shardNode.getLoader().isLoaded()) {
                        shardNode.getLoader().setLoaded(false);
                        shardNode.getChildren(monitor);
                    }
                }
                ((CubridShard) shardNode).setRunning(shardStatus != null);
                parent.addChild(shardNode);
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ShardStatus(com.cubrid.cubridmanager.core.shard.model.ShardStatus) ShardKeys(com.cubrid.cubridmanager.core.shard.model.ShardKeys) HashMap(java.util.HashMap) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) ShardConnection(com.cubrid.cubridmanager.core.shard.model.ShardConnection) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ShardsStatus(com.cubrid.cubridmanager.core.shard.model.ShardsStatus) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

CubridShard (com.cubrid.cubridmanager.ui.spi.model.CubridShard)6 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)3 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 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 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 Shard (com.cubrid.cubridmanager.core.shard.model.Shard)1 ShardConnection (com.cubrid.cubridmanager.core.shard.model.ShardConnection)1 ShardKeys (com.cubrid.cubridmanager.core.shard.model.ShardKeys)1 ShardStatus (com.cubrid.cubridmanager.core.shard.model.ShardStatus)1 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)1 ShardsStatus (com.cubrid.cubridmanager.core.shard.model.ShardsStatus)1 GetShardConfTask (com.cubrid.cubridmanager.core.shard.task.GetShardConfTask)1