diff options
| author | Alois Zoitl | 2018-09-17 08:41:25 +0000 |
|---|---|---|
| committer | Alois Zoitl | 2018-09-17 17:16:34 +0000 |
| commit | d333b5d7061ebc09b28e6145832a4117cf7fd179 (patch) | |
| tree | fe2f92d45c4382a03f89d7b9ee25eadd47773c59 | |
| parent | 4d7a4d751429326affa8a381a31ab6748750e8cc (diff) | |
| download | org.eclipse.4diac.ide-d333b5d7061ebc09b28e6145832a4117cf7fd179.tar.gz org.eclipse.4diac.ide-d333b5d7061ebc09b28e6145832a4117cf7fd179.tar.xz org.eclipse.4diac.ide-d333b5d7061ebc09b28e6145832a4117cf7fd179.zip | |
[539125] Introduced device deployment data
with this change the data required for deploying is extended with a
device deployment data class. This allows to make single connection to
devices and allowed a quite some cleanup in the runable performing the
deployment process.
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=539125
Change-Id: Ie4b55585fb1ba85bd15f18b9455e3bf7a4a5ed81
Signed-off-by: Alois Zoitl <alois.zoitl@gmx.at>
17 files changed, 368 insertions, 266 deletions
diff --git a/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DeploymentExecutor.java b/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DeploymentExecutor.java index a9883544a3..9412dcefd9 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DeploymentExecutor.java +++ b/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DeploymentExecutor.java @@ -29,8 +29,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; import org.eclipse.fordiac.ide.deployment.IDeviceManagementCommunicationHandler; -import org.eclipse.fordiac.ide.deployment.ConnectionDeploymentData; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ConnectionDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.devResponse.Response; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.interactors.AbstractDeviceManagementInteractor; diff --git a/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DynamicTypeLoadDeploymentExecutor.java b/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DynamicTypeLoadDeploymentExecutor.java index f5ef3975d4..457714d303 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DynamicTypeLoadDeploymentExecutor.java +++ b/plugins/org.eclipse.fordiac.ide.deployment.iec61499/src/org/eclipse/fordiac/ide/deployment/iec61499/DynamicTypeLoadDeploymentExecutor.java @@ -28,7 +28,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; import org.eclipse.fordiac.ide.deployment.IDeviceManagementCommunicationHandler; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.devResponse.Response; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.export.forte_lua.ForteLuaExportFilter; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.deployment/META-INF/MANIFEST.MF index 7e6c106012..4d50682c7a 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.deployment/META-INF/MANIFEST.MF @@ -1,5 +1,6 @@ Manifest-Version: 1.0 Export-Package: org.eclipse.fordiac.ide.deployment, + org.eclipse.fordiac.ide.deployment.data, org.eclipse.fordiac.ide.deployment.devResponse, org.eclipse.fordiac.ide.deployment.devResponse.impl, org.eclipse.fordiac.ide.deployment.devResponse.util, diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DeploymentCoordinator.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DeploymentCoordinator.java index 663868ec6d..01db2f414d 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DeploymentCoordinator.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DeploymentCoordinator.java @@ -10,22 +10,21 @@ * Contributors: * Gerhard Ebenhofer, Alois Zoitl, Monika Wenger * - initial API and implementation and/or initial documentation + * Alois Zoitl - reworked deployment to detect if monitoring was enabled *******************************************************************************/ package org.eclipse.fordiac.ide.deployment; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.fordiac.ide.deployment.ResourceDeploymentData.ParameterData; -import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; -import org.eclipse.fordiac.ide.deployment.interactors.DeviceManagementInteractorFactory; +import org.eclipse.fordiac.ide.deployment.data.DeviceDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ResourceDeploymentData; import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; -import org.eclipse.fordiac.ide.deployment.util.DeploymentHelper; import org.eclipse.fordiac.ide.deployment.util.IDeploymentListener; import org.eclipse.fordiac.ide.model.libraryElement.Device; import org.eclipse.fordiac.ide.model.libraryElement.FB; @@ -38,7 +37,6 @@ import org.eclipse.fordiac.ide.model.libraryElement.Value; import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; @@ -46,7 +44,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; -public class DeploymentCoordinator { +public final class DeploymentCoordinator { private static DeploymentCoordinator instance; private static final String OUTPUT_VIEW_ID = "org.eclipse.fordiac.ide.deployment.ui.views.Output"; @@ -79,7 +77,11 @@ public class DeploymentCoordinator { } public List<VarDeclaration> getSelectedDeviceProperties(Device dev) { - return deployedDeviceProperties.get(dev); + List<VarDeclaration> retVal = deployedDeviceProperties.get(dev); + if(null == retVal) { + retVal = Collections.emptyList(); + } + return retVal; } private DeploymentCoordinator() { @@ -92,222 +94,26 @@ public class DeploymentCoordinator { } return instance; } - - class DownloadRunnable implements IRunnableWithProgress { - private final List<Device> devices; - private final List<ResourceDeploymentData> resources; - private IDeviceManagementCommunicationHandler overrideDevMgmCommHandler; - private IDeploymentListener outputView; - private String profile; - - /** - * DownloadRunnable constructor. - * - * @param work the amount of download operations - * @param selection the selection - * @param overrideDevMgmCommHandler if not null this device management - * communication should be used instead the one - * derived from the device profile. - */ - public DownloadRunnable( - final List<Device> devices, - final List<ResourceDeploymentData> resources, - IDeviceManagementCommunicationHandler overrideDevMgmCommHandler, - IDeploymentListener outputView, String profile) { - this.devices = devices; - this.resources = resources; - this.overrideDevMgmCommHandler = overrideDevMgmCommHandler; - this.outputView = outputView; - this.profile = profile; - } - - /** - * Runs the check. - * - * @param monitor the progress monitor - * - * @throws InvocationTargetException the invocation target exception - * @throws InterruptedException the interrupted exception - */ - @Override - public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask(Messages.DeploymentCoordinator_LABEL_PerformingDownload, calculateWorkAmount()); - - for (ResourceDeploymentData resDepData : resources) { - if (monitor.isCanceled()) { - throw new InterruptedException(Messages.DeploymentCoordinator_LABEL_DownloadAborted); - } - - IDeviceManagementInteractor executor = DeviceManagementInteractorFactory.INSTANCE.getDeviceManagementInteractor(resDepData.res.getDevice(), overrideDevMgmCommHandler, profile); - - if (executor != null) { - - if (null != outputView) { //TODO: Add outputView as listener only when actually deploying from the Deployment View - executor.addDeploymentListener(outputView); - } - - try { - deployResource(monitor, resDepData, executor); - } catch (final Exception e) { - Display.getDefault().asyncExec(() -> { - final Shell shell = Display.getDefault().getActiveShell(); - - MessageDialog.openError(shell, "Major Download Error", - "Resource: " + resDepData.res.getDevice().getName() + "." - + resDepData.res.getName() + "\n" + "MGR_ID: " - + DeploymentHelper.getMgrID(resDepData.res.getDevice()) + "\n" - + "Problem: " + e.getMessage()); - }); - } - - if (null != outputView) { - executor.removeDeploymentListener((IDeploymentListener) outputView); - } - - } else { - printUnsupportedDeviceProfileMessageBox(resDepData.res.getDevice(), resDepData.res); - } - } - for (Device device : devices) { - configureDevice(monitor, device); - if (monitor.isCanceled()) { - throw new InterruptedException(Messages.DeploymentCoordinator_LABEL_DownloadAborted); - } - } - monitor.done(); - } - - private int calculateWorkAmount() { - int retVal = devices.size() + resources.size(); - for (ResourceDeploymentData resDepData : resources) { - retVal += countResourceParams(resDepData.res); - retVal += resDepData.fbs.size() + resDepData.connections.size() + resDepData.params.size(); - // TODO count variables of Fbs - } - return retVal; - } - - private int countResourceParams(final Resource res) { - int work = 0; - for (VarDeclaration varDecl : res.getVarDeclarations()) { - if (varDecl.getValue() != null && varDecl.getValue().getValue() != null - && varDecl.getValue().getValue().equals("")) { //$NON-NLS-1$ - work++; - } - } - return work; - } - - protected void deployResource(final IProgressMonitor monitor, final ResourceDeploymentData resDepData, - IDeviceManagementInteractor executor) throws DeploymentException { - Resource res = resDepData.res; - if (!res.isDeviceTypeResource()) { - try { //this try catch block with rethrowing is needed so that we can have the finally statement for disconnecting - executor.connect(); - executor.createResource(res); - monitor.worked(1); - for (VarDeclaration varDecl : res.getVarDeclarations()) { - String val = DeploymentHelper.getVariableValue(varDecl, res.getAutomationSystem()); - if (null != val) { - executor.writeResourceParameter(res, varDecl.getName(), val); - monitor.worked(1); - } - } - - createFBInstance(resDepData, executor, monitor); - deployParamters(resDepData, executor, monitor); // this needs to be done before the connections are - // created - deployConnections(resDepData, executor, monitor); - - if (!devices.contains(res.getDevice())) { - executor.startResource(res); - } else { - // resource is started when device is - // started - } - } finally { - executor.disconnect(); - } - } - } - - private void configureDevice(final IProgressMonitor monitor, Device device) { - IDeviceManagementInteractor executor = DeviceManagementInteractorFactory.INSTANCE - .getDeviceManagementInteractor(device, overrideDevMgmCommHandler, null); - List<VarDeclaration> parameters = getSelectedDeviceProperties(device); - - if (executor != null && parameters != null && !parameters.isEmpty()) { - try { - executor.connect(); - for (VarDeclaration varDeclaration : parameters) { - String value = DeploymentHelper.getVariableValue(varDeclaration, device.getAutomationSystem()); - if (null != value) { - executor.writeDeviceParameter(device, varDeclaration.getName(), value); - } - } - executor.startDevice(device); - monitor.worked(1); - } catch (Exception e) { - // TODO model refactoring - show error message to user - Activator.getDefault().logError(e.getMessage(), e); - } finally { - try { - executor.disconnect(); - } catch (DeploymentException e) { - // TODO model refactoring - show error message to user - Activator.getDefault().logError(e.getMessage(), e); - } - } - } - } - - private void deployParamters(ResourceDeploymentData resDepData, IDeviceManagementInteractor executor, - IProgressMonitor monitor) throws DeploymentException { - for (ParameterData param : resDepData.params) { - executor.writeFBParameter(resDepData.res, param.value, - new FBDeploymentData(param.prefix, (FB) param.var.getFBNetworkElement()), param.var); - monitor.worked(1); - } - - } - - private void deployConnections(final ResourceDeploymentData resDepData, - final IDeviceManagementInteractor executor, IProgressMonitor monitor) throws DeploymentException { - for (ConnectionDeploymentData con : resDepData.connections) { - // TODO model refactoring - if one connection endpoint is part of resource find - // inner endpoint - executor.createConnection(resDepData.res, con); - monitor.worked(1); - if (monitor.isCanceled()) { - break; - } - } - } + public static void printUnsupportedDeviceProfileMessageBox(final Device device, final Resource res) { + Display.getDefault().asyncExec(() -> { + MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + SWT.ICON_ERROR | SWT.OK); + String resName = (null != res) ? res.getName() : ""; //$NON-NLS-1$ - private void createFBInstance(final ResourceDeploymentData resDepData, - final IDeviceManagementInteractor executor, final IProgressMonitor monitor) throws DeploymentException { - Resource res = resDepData.res; - for (FBDeploymentData fb : resDepData.fbs) { - if (!fb.fb.isResourceTypeFB()) { - executor.createFBInstance(fb, res); - monitor.worked(1); - InterfaceList interfaceList = fb.fb.getInterface(); - if (interfaceList != null) { - for (VarDeclaration varDecl : interfaceList.getInputVars()) { - String val = DeploymentHelper.getVariableValue(varDecl, res.getAutomationSystem()); - if (null != val) { - executor.writeFBParameter(res, val, fb, varDecl); - monitor.worked(1); - } - } - } - } + if (null != device.getProfile() && !device.getProfile().equals("")) { //$NON-NLS-1$ + messageBox.setMessage( + MessageFormat.format(Messages.DeploymentCoordinator_MESSAGE_DefinedProfileNotSupported, + device.getProfile(), device.getName(), resName)); + } else { + messageBox.setMessage(MessageFormat.format(Messages.DeploymentCoordinator_MESSAGE_ProfileNotSet, + device.getName(), resName)); } - } - + messageBox.open(); + }); } + /** * Count work creating f bs. * @@ -342,23 +148,6 @@ public class DeploymentCoordinator { return work; } - public static void printUnsupportedDeviceProfileMessageBox(final Device device, final Resource res) { - Display.getDefault().syncExec(() -> { - MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - SWT.ICON_ERROR | SWT.OK); - String resName = (null != res) ? res.getName() : ""; //$NON-NLS-1$ - - if (null != device.getProfile() && !device.getProfile().equals("")) { //$NON-NLS-1$ - messageBox.setMessage( - MessageFormat.format(Messages.DeploymentCoordinator_MESSAGE_DefinedProfileNotSupported, - device.getProfile(), device.getName(), resName)); - } else { - messageBox.setMessage(MessageFormat.format(Messages.DeploymentCoordinator_MESSAGE_ProfileNotSet, - device.getName(), resName)); - } - messageBox.open(); - }); - } /** * Perform deployment. @@ -369,22 +158,8 @@ public class DeploymentCoordinator { * derived from the device profile. */ public void performDeployment(final Object[] selection, IDeviceManagementCommunicationHandler overrideDevMgmCommHandler, String profile) { - List<Device> devices = new ArrayList<>(); - List<ResourceDeploymentData> resDepData = new ArrayList<>(); - for (int i = 0; i < selection.length; i++) { - Object object = selection[i]; - if (object instanceof Resource) { - resDepData.add(new ResourceDeploymentData((Resource) object)); - } else if (object instanceof Device) { - List<VarDeclaration> parameters = getSelectedDeviceProperties((Device) object); - if (parameters != null && !parameters.isEmpty()) { - devices.add((Device) object); - } - } - } - IDeploymentListener outputView = (IDeploymentListener)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .findView(OUTPUT_VIEW_ID); - DownloadRunnable download = new DownloadRunnable(devices, resDepData, overrideDevMgmCommHandler, outputView, profile); + IDeploymentListener outputView = (IDeploymentListener)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(OUTPUT_VIEW_ID); + DownloadRunnable download = new DownloadRunnable(createDeploymentdata(selection), overrideDevMgmCommHandler, outputView, profile); Shell shell = Display.getDefault().getActiveShell(); try { new ProgressMonitorDialog(shell).run(true, true, download); @@ -423,4 +198,36 @@ public class DeploymentCoordinator { interactor.removeDeploymentListener((IDeploymentListener)view); } } + + private List<DeviceDeploymentData> createDeploymentdata(Object[] selection) { + List<DeviceDeploymentData> data = new ArrayList<>(); + for (Object object : selection) { + if (object instanceof Resource) { + Resource res = (Resource)object; + DeviceDeploymentData devData = getDevData(data, res.getDevice()); + devData.addResourceData(new ResourceDeploymentData(res)); + } else if (object instanceof Device) { + Device dev = (Device) object; + DeviceDeploymentData devData = getDevData(data, dev); + devData.setSeltectedDevParams(getSelectedDeviceProperties((Device) object)); + } + } + return data; + } + + private static DeviceDeploymentData getDevData(List<DeviceDeploymentData> data, final Device device) { + DeviceDeploymentData retVal = null; + for(DeviceDeploymentData devData : data) { + if(device == devData.getDevice()) { + retVal = devData; + break; + } + } + if(null == retVal) { + retVal = new DeviceDeploymentData(device); + data.add(retVal); + } + return retVal; + } + } diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DownloadRunnable.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DownloadRunnable.java new file mode 100644 index 0000000000..b09ebae8f5 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/DownloadRunnable.java @@ -0,0 +1,233 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2018 Profactor GmbH, fortiss GmbH, + * Johannes Kepler University + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerhard Ebenhofer, Alois Zoitl, Monika Wenger + * - initial API and implementation and/or initial documentation + * Alois Zoitl - reworked deployment to detect if monitoring was enabled + *******************************************************************************/ +package org.eclipse.fordiac.ide.deployment; + +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.fordiac.ide.deployment.data.ConnectionDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.DeviceDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ResourceDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ResourceDeploymentData.ParameterData; +import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; +import org.eclipse.fordiac.ide.deployment.interactors.DeviceManagementInteractorFactory; +import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; +import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor.IDeviceManagementInteractorCloser; +import org.eclipse.fordiac.ide.deployment.util.DeploymentHelper; +import org.eclipse.fordiac.ide.deployment.util.IDeploymentListener; +import org.eclipse.fordiac.ide.model.libraryElement.Device; +import org.eclipse.fordiac.ide.model.libraryElement.FB; +import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList; +import org.eclipse.fordiac.ide.model.libraryElement.Resource; +import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +class DownloadRunnable implements IRunnableWithProgress { + + private final List<DeviceDeploymentData> deploymentData; + private final IDeviceManagementCommunicationHandler overrideDevMgmCommHandler; + private final IDeploymentListener outputView; + private final String profile; + private IProgressMonitor curMonitor; + + /** + * DownloadRunnable constructor. + * + * @param deploymentData the collection of elements to deploy + * @param overrideDevMgmCommHandler if not null this device management + * communication should be used instead the one + * derived from the device profile. + * @param outputView the view showing the download information + * @param profile if not null the profile to be used instead of the device's profile + */ + public DownloadRunnable(final List<DeviceDeploymentData> deploymentData, + IDeviceManagementCommunicationHandler overrideDevMgmCommHandler, IDeploymentListener outputView, + String profile) { + this.deploymentData = deploymentData; + this.overrideDevMgmCommHandler = overrideDevMgmCommHandler; + this.outputView = outputView; + this.profile = profile; + } + + /** + * Runs the check. + * + * @param monitor the progress monitor + * + * @throws InvocationTargetException the invocation target exception + * @throws InterruptedException the interrupted exception + */ + @Override + public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + this.curMonitor = monitor; + monitor.beginTask(Messages.DeploymentCoordinator_LABEL_PerformingDownload, calculateWorkAmount()); + + for(DeviceDeploymentData devData : deploymentData) { + if (monitor.isCanceled()) { + throw new InterruptedException(Messages.DeploymentCoordinator_LABEL_DownloadAborted); + } + IDeviceManagementInteractor executor = DeviceManagementInteractorFactory.INSTANCE.getDeviceManagementInteractor(devData.getDevice(), overrideDevMgmCommHandler, profile); + if (executor != null) { + addDeploymentListener(executor); + try(IDeviceManagementInteractorCloser closer = executor::disconnect){ + executor.connect(); + deployResources(devData, executor); + deployDevice(devData, executor); + }catch (final DeploymentException e) { + showDeploymentErrorDialog(devData.getDevice(), e); + }finally{ + removeDeploymentListener(executor); + } + + } else { + DeploymentCoordinator.printUnsupportedDeviceProfileMessageBox(devData.getDevice(), null); + } + } + monitor.done(); + } + + private void deployResources(DeviceDeploymentData devData, IDeviceManagementInteractor executor) throws InterruptedException, DeploymentException { + for (ResourceDeploymentData resData : devData.getResData()) { + if (curMonitor.isCanceled()) { + throw new InterruptedException(Messages.DeploymentCoordinator_LABEL_DownloadAborted); + } + deployResource(resData, executor); + executor.startResource(resData.res); + } + } + + private void deployDevice(DeviceDeploymentData devData, IDeviceManagementInteractor executor) throws DeploymentException { + Device device = devData.getDevice(); + + for(VarDeclaration var : devData.getSelectedDevParams()) { + String value = DeploymentHelper.getVariableValue(var, device.getAutomationSystem()); + if (null != value) { + executor.writeDeviceParameter(device, var.getName(), value); + } + curMonitor.worked(1); + } + } + + private static void showDeploymentErrorDialog(Device device, DeploymentException e) { + Display.getDefault().asyncExec(() -> { + final Shell shell = Display.getDefault().getActiveShell(); + MessageDialog.openError(shell, Messages.DownloadRunnable_MajorDownloadError, + MessageFormat.format(Messages.DownloadRunnable_DownloadErrorDetails, device.getName(), DeploymentHelper.getMgrID(device), e.getMessage())); + }); + } + + private void addDeploymentListener(IDeviceManagementInteractor executor) { + if (null != outputView) { + executor.addDeploymentListener(outputView); + } + } + + private void removeDeploymentListener(IDeviceManagementInteractor executor) { + if (null != outputView) { + executor.removeDeploymentListener(outputView); + } + } + + private int calculateWorkAmount() { + int retVal = deploymentData.size(); + + for (DeviceDeploymentData devData : deploymentData) { + retVal += devData.getSelectedDevParams().size(); + retVal += devData.getResData().size(); + for (ResourceDeploymentData resDepData : devData.getResData()) { + retVal += countResourceParams(resDepData.res); + retVal += resDepData.fbs.size() + resDepData.connections.size() + resDepData.params.size(); + // TODO count variables of Fbs + } + } + return retVal; + } + + private static int countResourceParams(final Resource res) { + int work = 0; + for (VarDeclaration varDecl : res.getVarDeclarations()) { + if (varDecl.getValue() != null && varDecl.getValue().getValue() != null + && varDecl.getValue().getValue().equals("")) { //$NON-NLS-1$ + work++; + } + } + return work; + } + + protected void deployResource(final ResourceDeploymentData resDepData, + IDeviceManagementInteractor executor) throws DeploymentException { + Resource res = resDepData.res; + if (!res.isDeviceTypeResource()) { + executor.createResource(res); + curMonitor.worked(1); + for (VarDeclaration varDecl : res.getVarDeclarations()) { + String val = DeploymentHelper.getVariableValue(varDecl, res.getAutomationSystem()); + if (null != val) { + executor.writeResourceParameter(res, varDecl.getName(), val); + curMonitor.worked(1); + } + } + createFBInstance(resDepData, executor); + deployParamters(resDepData, executor); // this needs to be done before the connections are created + deployConnections(resDepData, executor); + } + } + + private void deployParamters(ResourceDeploymentData resDepData, IDeviceManagementInteractor executor) throws DeploymentException { + for (ParameterData param : resDepData.params) { + executor.writeFBParameter(resDepData.res, param.value, + new FBDeploymentData(param.prefix, (FB) param.var.getFBNetworkElement()), param.var); + curMonitor.worked(1); + } + } + + private void deployConnections(final ResourceDeploymentData resDepData, + final IDeviceManagementInteractor executor) throws DeploymentException { + for (ConnectionDeploymentData con : resDepData.connections) { + executor.createConnection(resDepData.res, con); + curMonitor.worked(1); + if (curMonitor.isCanceled()) { + break; + } + } + } + + private void createFBInstance(final ResourceDeploymentData resDepData, final IDeviceManagementInteractor executor) throws DeploymentException { + Resource res = resDepData.res; + for (FBDeploymentData fbDepData : resDepData.fbs) { + if (!fbDepData.fb.isResourceTypeFB()) { + executor.createFBInstance(fbDepData, res); + curMonitor.worked(1); + InterfaceList interfaceList = fbDepData.fb.getInterface(); + if (interfaceList != null) { + for (VarDeclaration varDecl : interfaceList.getInputVars()) { + String val = DeploymentHelper.getVariableValue(varDecl, res.getAutomationSystem()); + if (null != val) { + executor.writeFBParameter(res, val, fbDepData, varDecl); + curMonitor.worked(1); + } + } + } + } + } + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/Messages.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/Messages.java index 7fff71b3bc..d29c58c02e 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/Messages.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/Messages.java @@ -34,6 +34,10 @@ public class Messages extends NLS { public static String DeploymentCoordinator_MESSAGE_ProfileNotSet; + public static String DownloadRunnable_DownloadErrorDetails; + + public static String DownloadRunnable_MajorDownloadError; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/ConnectionDeploymentData.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/ConnectionDeploymentData.java index a6ff07e03e..602b5ae70a 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/ConnectionDeploymentData.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/ConnectionDeploymentData.java @@ -8,7 +8,7 @@ * Contributors: * Alois Zoitl - initial API and implementation and/or initial documentation *******************************************************************************/ -package org.eclipse.fordiac.ide.deployment; +package org.eclipse.fordiac.ide.deployment.data; import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/DeviceDeploymentData.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/DeviceDeploymentData.java new file mode 100644 index 0000000000..d3bba3ca26 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/DeviceDeploymentData.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2018 Johannes Kepler University + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.fordiac.ide.deployment.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.fordiac.ide.model.libraryElement.Device; +import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration; + +public class DeviceDeploymentData { + + private final Device dev; + + private List<ResourceDeploymentData> resData = new ArrayList<>(); + + private List<VarDeclaration> selectedDevParams = Collections.emptyList(); + + public DeviceDeploymentData(Device device) { + dev = device; + } + + public Device getDevice() { + return dev; + } + + public void addResourceData(ResourceDeploymentData data) { + resData.add(data); + } + + public List<ResourceDeploymentData> getResData(){ + return resData; + } + + public void setSeltectedDevParams(List<VarDeclaration> selParams) { + selectedDevParams = Collections.unmodifiableList(new ArrayList<>(selParams)); + } + + + /**Get the unmodifyable list of the selecte params to be downloaded to this device + */ + public List<VarDeclaration> getSelectedDevParams(){ + return selectedDevParams; + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/FBDeploymentData.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/FBDeploymentData.java index bddd9f412e..64d702456d 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/FBDeploymentData.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/FBDeploymentData.java @@ -10,7 +10,7 @@ * Alois Zoitl * - initial API and implementation and/or initial documentation *******************************************************************************/ -package org.eclipse.fordiac.ide.deployment; +package org.eclipse.fordiac.ide.deployment.data; import org.eclipse.fordiac.ide.model.libraryElement.FB; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/ResourceDeploymentData.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/ResourceDeploymentData.java index 4b5c80ece1..c6ba33b2b9 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/ResourceDeploymentData.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/data/ResourceDeploymentData.java @@ -8,7 +8,7 @@ * Contributors: * Alois Zoitl - initial API and implementation and/or initial documentation *******************************************************************************/ -package org.eclipse.fordiac.ide.deployment; +package org.eclipse.fordiac.ide.deployment.data; import java.util.ArrayDeque; import java.util.ArrayList; @@ -31,7 +31,7 @@ import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration; * This is the FBs collected from the resource and the mapped subapps as well as the connections and the * subapp interface crossing connections */ -class ResourceDeploymentData { +public class ResourceDeploymentData { public class ParameterData{ public String value; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/DeviceManagementInteractorFactory.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/DeviceManagementInteractorFactory.java index af0c8b6a9c..dde5080b70 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/DeviceManagementInteractorFactory.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/DeviceManagementInteractorFactory.java @@ -21,8 +21,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; -import org.eclipse.fordiac.ide.deployment.IDeviceManagementCommunicationHandler; import org.eclipse.fordiac.ide.deployment.Activator; +import org.eclipse.fordiac.ide.deployment.IDeviceManagementCommunicationHandler; import org.eclipse.fordiac.ide.deployment.Messages; import org.eclipse.fordiac.ide.model.libraryElement.Device; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/IDeviceManagementInteractor.java b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/IDeviceManagementInteractor.java index dcd7d2f7c7..993d1eea52 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/IDeviceManagementInteractor.java +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/interactors/IDeviceManagementInteractor.java @@ -14,8 +14,8 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.deployment.interactors; -import org.eclipse.fordiac.ide.deployment.ConnectionDeploymentData; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ConnectionDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.devResponse.Response; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.monitoringbase.MonitoringBaseElement; diff --git a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/messages.properties b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/messages.properties index 60f10cedff..04348a14ac 100644 --- a/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.deployment/src/org/eclipse/fordiac/ide/deployment/messages.properties @@ -16,3 +16,5 @@ DeploymentCoordinator_MESSAGE_ProfileNotSet=Download not possible\! No profile s DeploymentCoordinator_LABEL_DownloadAborted=Download Aborted DeploymentCoordinator_ERROR_Message=Something's wrong. +DownloadRunnable_DownloadErrorDetails=Device: {0}\nMGR_ID: {1}\nProblem: {2} +DownloadRunnable_MajorDownloadError=Major Download Error diff --git a/plugins/org.eclipse.fordiac.ide.monitoring/src/org/eclipse/fordiac/ide/monitoring/MonitoringManager.java b/plugins/org.eclipse.fordiac.ide.monitoring/src/org/eclipse/fordiac/ide/monitoring/MonitoringManager.java index 51918406e7..72ee9c8a07 100644 --- a/plugins/org.eclipse.fordiac.ide.monitoring/src/org/eclipse/fordiac/ide/monitoring/MonitoringManager.java +++ b/plugins/org.eclipse.fordiac.ide.monitoring/src/org/eclipse/fordiac/ide/monitoring/MonitoringManager.java @@ -20,7 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; import org.eclipse.fordiac.ide.deployment.monitoringbase.AbstractMonitoringManager; diff --git a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateConnectionHandler.java b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateConnectionHandler.java index 5b9c1812ae..30b6cedfab 100644 --- a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateConnectionHandler.java +++ b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateConnectionHandler.java @@ -14,7 +14,7 @@ package org.eclipse.fordiac.ide.onlineedit.handlers; import java.util.List; -import org.eclipse.fordiac.ide.deployment.ConnectionDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.ConnectionDeploymentData; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; import org.eclipse.fordiac.ide.deployment.ui.handlers.AbstractDeploymentCommand; diff --git a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateFBHandler.java b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateFBHandler.java index 0b48081643..a4bb9aae7c 100644 --- a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateFBHandler.java +++ b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineCreateFBHandler.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.onlineedit.handlers; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; diff --git a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineStartFBHandler.java b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineStartFBHandler.java index fadd42973d..eaa44cbae2 100644 --- a/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineStartFBHandler.java +++ b/plugins/org.eclipse.fordiac.ide.onlineedit/src/org/eclipse/fordiac/ide/onlineedit/handlers/OnlineStartFBHandler.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.onlineedit.handlers; -import org.eclipse.fordiac.ide.deployment.FBDeploymentData; +import org.eclipse.fordiac.ide.deployment.data.FBDeploymentData; import org.eclipse.fordiac.ide.deployment.exceptions.DeploymentException; import org.eclipse.fordiac.ide.deployment.interactors.IDeviceManagementInteractor; |
