Search in sources :

Example 16 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand 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 17 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand 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 18 with AbstractDeployCommand

use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand 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 19 with AbstractDeployCommand

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

the class CommandManager method getAllDeployCommands.

public List<AbstractDeployCommand> getAllDeployCommands() {
    List<AbstractDeployCommand> cmds = new ArrayList<AbstractDeployCommand>();
    for (CommandStack stack : map.values()) {
        ICommand validCommand = stack.getValidDeployCommand();
        if (validCommand != null) {
            if (validCommand instanceof AbstractDeployCommand) {
                fillViewObjectToCommand(validCommand);
                AbstractDeployCommand deployCommand = (AbstractDeployCommand) validCommand;
                cmds.add(deployCommand);
            }
        }
    }
    return cmds;
}
Also used : ArrayList(java.util.ArrayList) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)

Example 20 with AbstractDeployCommand

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

the class CommandManager method convertToDeployCompundCommands.

public List<ICommand> convertToDeployCompundCommands(List<AbstractDeployCommand> validCommands, MDMServerDef serverDef) {
    List<ICommand> cmds = new ArrayList<ICommand>(validCommands.size());
    for (AbstractDeployCommand deployCommand : validCommands) {
        deployCommand.setServerDef(serverDef);
        ICommand newCmd = convertToDeployCompoundCommand(deployCommand);
        cmds.add(newCmd);
    }
    return cmds;
}
Also used : ArrayList(java.util.ArrayList) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)

Aggregations

AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)21 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 CommandManager (org.talend.mdm.repository.core.command.CommandManager)8 IStatus (org.eclipse.core.runtime.IStatus)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 ICommand (org.talend.mdm.repository.core.command.ICommand)6 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)5 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)4 Test (org.junit.Test)3 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)3 IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 HashSet (java.util.HashSet)2 WebServiceException (javax.xml.ws.WebServiceException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Property (org.talend.core.model.properties.Property)2 CommandStack (org.talend.mdm.repository.core.command.CommandStack)2