use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class RemoveDuplicatedContextGroupMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
List<?> contexts = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
}
Set<String> nameSet = new HashSet<String>();
Iterator<?> iterator = contexts.listIterator();
int count = 0;
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextType) {
ContextType context = (ContextType) obj;
if (nameSet.contains(context.getName())) {
iterator.remove();
count++;
} else {
nameSet.add(context.getName());
}
}
}
if (count > 0) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
EList<ContextType> contexts = null;
String defualtGroupName = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
defualtGroupName = processItem.getProcess().getDefaultContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
} else if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
contexts = contextItem.getContext();
defualtGroupName = contextItem.getDefaultContext();
}
try {
ContextType defaultGroup = null;
for (ContextType context : contexts) {
if (context.getName().equals(defualtGroupName)) {
defaultGroup = context;
break;
}
}
if (defaultGroup == null && contexts.size() > 0) {
defaultGroup = contexts.get(0);
}
boolean contextChanged = false;
if (defaultGroup != null) {
Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
List<String> paramNameList = new ArrayList<String>();
paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
for (ContextType context : contexts) {
if (context == defaultGroup) {
continue;
}
Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
for (String paramName : otherGroupParam.keySet()) {
if (!paramMap.containsKey(paramName)) {
paramMap.put(paramName, otherGroupParam.get(paramName));
}
}
}
// make sure all groups have the same param list
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<String> paramNames = new ArrayList<String>(paramNameList);
for (ContextParameterType param : params) {
if (paramNames.contains(param.getName())) {
paramNames.remove(param.getName());
}
}
if (!paramNames.isEmpty()) {
contextChanged = true;
for (String paramToAdd : paramNames) {
ContextParameterType toAdd = paramMap.get(paramToAdd);
context.getContextParameter().add(EcoreUtil.copy(toAdd));
}
}
}
// change param order if needed
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
for (int i = 0; i < copyOfParam.size(); i++) {
ContextParameterType param = copyOfParam.get(i);
int indexOf = paramNameList.indexOf(param.getName());
if (i != indexOf) {
contextChanged = true;
params.remove(param);
params.add(indexOf, param);
}
}
}
// make sure params in different groups have the same repository id and type as default group
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
for (ContextParameterType param : params) {
ContextParameterType paramDefault = paramMap.get(param.getName());
if (!paramDefault.getType().equals(param.getType())) {
contextChanged = true;
param.setType(paramDefault.getType());
}
if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
contextChanged = true;
param.setRepositoryContextId(paramDefault.getRepositoryContextId());
}
}
}
}
if (contextChanged) {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method updateCodeEditorContent.
private void updateCodeEditorContent() {
if (!(processor.getProperty().getItem() instanceof JobletProcessItem)) {
FileEditorInput input = createFileEditorInput();
codeEditor.setInput(input);
}
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method covertJobscriptOnPageChange.
private void covertJobscriptOnPageChange() {
try {
boolean isDirty = jobletEditor.isDirty();
jobletEditor.doSave(null);
IProcess2 oldProcess = getProcess();
ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
Item item = oldProcess.getProperty().getItem();
ProcessType processType = null;
if (item instanceof ProcessItem) {
processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
} else if (item instanceof JobletProcessItem) {
processType = n.convertJobletDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
}
if (item instanceof ProcessItem) {
((Process) oldProcess).updateProcess(processType);
} else if (item instanceof JobletProcessItem) {
((Process) oldProcess).updateProcess(processType);
}
oldProcess.getUpdateManager().updateAll();
designerEditor.setDirty(isDirty);
List<Node> nodes = (List<Node>) oldProcess.getGraphicalNodes();
List<Node> newNodes = new ArrayList<Node>();
newNodes.addAll(nodes);
for (Node node : newNodes) {
node.getProcess().checkStartNodes();
node.checkAndRefreshNode();
IElementParameter ep = node.getElementParameter("ACTIVATE");
if (ep != null && ep.getValue().equals(Boolean.FALSE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
} else if (ep != null && ep.getValue().equals(Boolean.TRUE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
}
for (IElementParameter param : node.getElementParameters()) {
if (!param.getChildParameters().isEmpty()) {
if (param.getValue() != null && param.getValue() instanceof String && ((String) param.getValue()).contains(":")) {
String[] splited = ((String) param.getValue()).split(":");
String childNameNeeded = splited[0].trim();
String valueChild = TalendQuoteUtils.removeQuotes(splited[1].trim());
if (param.getChildParameters().containsKey(childNameNeeded)) {
param.getChildParameters().get(childNameNeeded).setValue(valueChild);
}
}
}
}
if (node.getNodeContainer() instanceof JobletContainer) {
JobletContainer jc = (JobletContainer) node.getNodeContainer();
if (node.isMapReduceStart()) {
//$NON-NLS-1$
jc.updateState("UPDATE_STATUS", "", jc.getPercentMap(), jc.getPercentReduce());
}
}
}
} catch (PersistenceException e) {
}
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method propaHadoopCfgChanges.
/**
* DOC ycbai Comment method "propaHadoopCfgChanges".
*
* <P>
* Propagate the changes from hadoop cluster to M/R process when drag&drop hadoop subnode from repository view to
* M/R process.
* </P>
*
* @param repositoryNode
*/
private void propaHadoopCfgChanges(IRepositoryNode repositoryNode) {
if (repositoryNode == null || repositoryNode.getObject() == null) {
return;
}
IHadoopClusterService hadoopClusterService = HadoopRepositoryUtil.getHadoopClusterService();
if (hadoopClusterService == null || !hadoopClusterService.isHadoopSubnode(repositoryNode)) {
return;
}
IProcess process = editor.getProcess();
if (!ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
return;
}
if ((process instanceof IProcess2) && (((IProcess2) process).getProperty().getItem() instanceof JobletProcessItem)) {
return;
}
Item subItem = repositoryNode.getObject().getProperty().getItem();
String propertyParamName = MR_PROPERTY_PREFIX + EParameterName.PROPERTY_TYPE.getName();
String propertyRepTypeParamName = MR_PROPERTY_PREFIX + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
IElementParameter propertyParam = process.getElementParameter(propertyParamName);
if (propertyParam == null) {
return;
}
String repositoryValue = propertyParam.getRepositoryValue();
if (repositoryValue == null) {
return;
}
//$NON-NLS-1$
String[] supportedRepositoryTypes = repositoryValue.split("\\|");
String repositoryType = hadoopClusterService.getRepositoryTypeOfHadoopSubItem(subItem);
if (!ArrayUtils.contains(supportedRepositoryTypes, repositoryType)) {
return;
}
Item hadoopClusterItem = hadoopClusterService.getHadoopClusterBySubitemId(new Project(ProjectManager.getInstance().getProject(subItem)), subItem.getProperty().getId());
String hadoopClusterId = hadoopClusterItem.getProperty().getId();
if (EmfComponent.REPOSITORY.equals(propertyParam.getValue())) {
// do nothing when select the same hadoop cluster.
String propertyId = (String) process.getElementParameter(propertyRepTypeParamName).getValue();
if (hadoopClusterId.equals(propertyId)) {
return;
}
}
Connection connection = ((ConnectionItem) subItem).getConnection();
if (hadoopClusterService.hasDiffsFromClusterToProcess(subItem, process)) {
boolean confirmUpdate = MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.msg"));
if (confirmUpdate) {
// Update spark mode to YARN_CLIENT if repository
if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
IElementParameter sparkLocalParam = process.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
IElementParameter sparkParam = process.getElementParameter(HadoopConstants.SPARK_MODE);
if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
sparkLocalParam.setValue(false);
}
if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
}
}
propertyParam.setValue(EmfComponent.REPOSITORY);
ChangeValuesFromRepository command = new ChangeValuesFromRepository(process, connection, propertyRepTypeParamName, subItem.getProperty().getId());
execCommandStack(command);
}
}
}
Aggregations