Search in sources :

Example 11 with CommandManager

use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.

the class DeployService method runCommands.

public IStatus runCommands(List<AbstractDeployCommand> commands, MDMServerDef serverDef) {
    reorderCommandObjects(commands);
    CommandManager manager = CommandManager.getInstance();
    List<ICommand> compundCommands = manager.convertToDeployCompundCommands(commands, serverDef);
    manager.arrangeForJobCommands(compundCommands);
    // 
    try {
        IProgressService progressService = null;
        if (PlatformUI.isWorkbenchRunning()) {
            progressService = PlatformUI.getWorkbench().getProgressService();
        } else {
            progressService = ConsoleProgressService.getInstance();
        }
        DeployProcess runnable = new DeployProcess(compundCommands);
        progressService.run(true, true, runnable);
        return runnable.getStatus();
    } catch (InvocationTargetException e) {
        log.error(e.getMessage(), e);
    } catch (InterruptedException e) {
    }
    return Status.CANCEL_STATUS;
}
Also used : CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) IProgressService(org.eclipse.ui.progress.IProgressService) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with CommandManager

use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.

the class DeployService method deploy.

public IStatus deploy(MDMServerDef serverDef, List<IRepositoryViewObject> viewObjs, int defaultCmdType, boolean removeLocked) {
    if (removeLocked) {
        removeLockedViewObj(viewObjs);
    }
    IModelValidateResult validateResult = validateModel(viewObjs);
    int selectedButton = validateResult.getSelectedButton();
    if (selectedButton == IModelValidationService.BUTTON_CANCEL) {
        return Status.CANCEL_STATUS;
    }
    List<IRepositoryViewObject> validObjects = validateResult.getValidObjects(selectedButton);
    List<IRepositoryViewObject> invalidObjects = validateResult.getInvalidObjects(selectedButton);
    try {
        // consistency check
        ConsistencyCheckResult consistencyCheckResult = ConsistencyService.getInstance().checkConsistency(serverDef, validObjects);
        if (consistencyCheckResult == null || consistencyCheckResult.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        validObjects = consistencyCheckResult.getToDeployObjects();
        // 
        CommandManager manager = CommandManager.getInstance();
        List<AbstractDeployCommand> commands = manager.getDeployCommands(validObjects, defaultCmdType);
        // insert impact dialog
        List<AbstractDeployCommand> canceledCommandAfterImpactAnalysis = new LinkedList<AbstractDeployCommand>(commands);
        if (UIUtil.isWorkInUI()) {
            try {
                Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = ModelImpactAnalyseService.analyzeCommandImpact(serverDef, commands);
                Map<IRepositoryViewObject, ICommandParameter> paramMap = null;
                if (analyzeModelImpact != null) {
                    ModelImpactAnalyseService.shrinkDeployCommands(analyzeModelImpact, commands);
                    paramMap = ModelImpactAnalyseService.convertToParameters(analyzeModelImpact);
                    manager.attachParameterToCommand(commands, paramMap);
                }
                canceledCommandAfterImpactAnalysis.removeAll(commands);
            } catch (InterruptedException ex) {
                return Status.CANCEL_STATUS;
            }
        }
        IStatus mainStatus = runCommands(commands, serverDef);
        // update consistency value
        try {
            updateServerConsistencyStatus(serverDef, mainStatus);
        } catch (XtentisException e) {
            log.error(e.getMessage(), e);
        } catch (WebServiceException e) {
            log.error(e.getMessage(), e);
        }
        // 
        generateValidationFailedDeployStatus(mainStatus, invalidObjects);
        if (UIUtil.isWorkInUI()) {
            generateConsistencyCancelDeployStatus(mainStatus, consistencyCheckResult.getToSkipObjects().toArray(new IRepositoryViewObject[0]));
            for (AbstractDeployCommand cmd : canceledCommandAfterImpactAnalysis) {
                generateConsistencyCancelDeployStatus(mainStatus, cmd.getViewObject());
            }
        }
        return mainStatus;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        String url = // $NON-NLS-1$
        serverDef.getProtocol() + serverDef.getHost() + ":" + serverDef.getPort() + serverDef.getPath();
        String title = Messages.bind(Messages.Server_cannot_connected, url);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, Messages.AbstractDataClusterAction_ConnectFailed);
        return Status.CANCEL_STATUS;
    }
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) IStatus(org.eclipse.core.runtime.IStatus) WebServiceException(javax.xml.ws.WebServiceException) ImpactOperation(org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation) ICommandParameter(org.talend.mdm.repository.core.command.param.ICommandParameter) LinkedList(java.util.LinkedList) XtentisException(com.amalto.workbench.utils.XtentisException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) XtentisException(com.amalto.workbench.utils.XtentisException)

Example 13 with CommandManager

use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.

the class DeployService method updateForStatus.

private void updateForStatus(boolean isUpdateServer, List<DeployStatus> deployStatuses) {
    if (deployStatuses == null || deployStatuses.size() == 0) {
        return;
    }
    for (DeployStatus deployStatus : deployStatuses) {
        if (deployStatus != null && deployStatus.isOK()) {
            ICommand command = deployStatus.getCommand();
            if (command != null) {
                CommandManager manager = CommandManager.getInstance();
                manager.removeCommandStack(command, ICommand.PHASE_DEPLOY);
                if (isUpdateServer) {
                    MDMServerDef serverDef = null;
                    if (command instanceof AbstractDeployCommand) {
                        serverDef = ((AbstractDeployCommand) command).getServerDef();
                    } else if (command instanceof DeployCompoundCommand) {
                        serverDef = ((DeployCompoundCommand) command).getServerDef();
                    }
                    if (command instanceof BatchDeployJobCommand) {
                        BatchDeployJobCommand deployJobCommand = (BatchDeployJobCommand) command;
                        pushRestoreCommand(manager, deployJobCommand.getSubCmds(), serverDef);
                        pushRestoreCommand(manager, deployJobCommand.getSubDeleteCmds(), serverDef);
                    } else {
                        // updateserver
                        pushRestoreCommand(manager, command, serverDef);
                    }
                }
            }
        }
    }
}
Also used : DeployCompoundCommand(org.talend.mdm.repository.core.command.deploy.DeployCompoundCommand) CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) BatchDeployJobCommand(org.talend.mdm.repository.core.command.deploy.job.BatchDeployJobCommand) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 14 with CommandManager

use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.

the class UndeployAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.mdm.repository.core.bridge.AbstractBridgeRepositoryAction#doRun()
     */
@Override
protected void doRun() {
    DeployService deployService = DeployService.getInstance();
    CommandManager cmanager = CommandManager.getInstance();
    List<IRepositoryViewObject> viewObjs = getSelectedRepositoryViewObject();
    if (viewObjs.size() < 1) {
        return;
    }
    SelectServerDefDialog dialog = getServerDefDialog(viewObjs);
    if (dialog.open() == IDialogConstants.OK_ID) {
        MDMServerDef serverDef = dialog.getSelectedServerDef();
        List<AbstractDeployCommand> deleteCommands = new ArrayList<AbstractDeployCommand>(viewObjs.size());
        for (IRepositoryViewObject obj : viewObjs) {
            ICommand deleteCmd = cmanager.getNewCommand(obj, ICommand.CMD_DELETE);
            deleteCmd.init(obj);
            deleteCommands.add((AbstractDeployCommand) deleteCmd);
        }
        IStatus status = deployService.runCommands(deleteCommands, serverDef);
        IProgressMonitor monitor = new NullProgressMonitor();
        deployService.updateChangedStatus(status);
        if (status.isMultiStatus()) {
            new DeployStatusDialog(getShell(), status).open();
        }
        for (IRepositoryViewObject viewObj : viewObjs) {
            MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(viewObj);
            String id = viewObj.getId();
            CommandStack stack = cmanager.findCommandStack(id);
            if (stack != null) {
                if (RepositoryResourceUtil.isSameMDMServerDef(lastServerDef, serverDef)) {
                    List<ICommand> commands = stack.getCommands(ICommand.PHASE_RESTORE);
                    for (ICommand cmd : commands) {
                        cmd.execute(null, monitor);
                    }
                }
                cmanager.removeCommandStack(id, ICommand.PHASE_RESTORE);
                commonViewer.refresh(viewObj);
            }
        }
    } else {
        return;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommandStack(org.talend.mdm.repository.core.command.CommandStack) IStatus(org.eclipse.core.runtime.IStatus) DeployStatusDialog(org.talend.mdm.repository.ui.dialogs.deploy.DeployStatusDialog) ArrayList(java.util.ArrayList) DeployService(org.talend.mdm.repository.core.service.DeployService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SelectServerDefDialog(org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 15 with CommandManager

use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.

the class DeployCompoundCommand method breakUpRenameCommand.

protected void breakUpRenameCommand() {
    CommandManager manager = CommandManager.getInstance();
    // delete
    AbstractDeployCommand deleteCmd = (AbstractDeployCommand) manager.getNewCommand(CMD_DELETE);
    deleteCmd.init(commandId, getObjName());
    deleteCmd.updateViewObject(getViewObject());
    deleteCmd.setServerDef(serverDef);
    // modify
    AbstractDeployCommand modifyCmd = (AbstractDeployCommand) manager.getNewCommand(CMD_MODIFY);
    modifyCmd.init(commandId, getObjLastName());
    modifyCmd.updateViewObject(getViewObject());
    modifyCmd.setServerDef(serverDef);
    // 
    subCmds.add(deleteCmd);
    subCmds.add(modifyCmd);
}
Also used : CommandManager(org.talend.mdm.repository.core.command.CommandManager)

Aggregations

CommandManager (org.talend.mdm.repository.core.command.CommandManager)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)8 ICommand (org.talend.mdm.repository.core.command.ICommand)8 AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)8 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)6 ArrayList (java.util.ArrayList)5 IStatus (org.eclipse.core.runtime.IStatus)5 LinkedList (java.util.LinkedList)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CommandStack (org.talend.mdm.repository.core.command.CommandStack)2 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)2 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)2 IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)2 SelectServerDefDialog (org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog)2