Commit 559612aa authored by Simon Barner's avatar Simon Barner
Browse files

Remove deployment metamodel and migrators

Issue-Ref: 3676
Issue-Url: https://af3-developer.fortiss.org/issues/3676

Signed-off-by: Simon Barner's avatarSimon Barner <barner@fortiss.org>
parent c6f6eeb2
......@@ -23,8 +23,6 @@
<semanticResources>platform:/resource/org.fortiss.tooling.kernel/model/kernel.genmodel</semanticResources>
<semanticResources>platform:/resource/org.fortiss.af3.timing/model/timing.genmodel</semanticResources>
<semanticResources>platform:/resource/org.fortiss.af3.schedule/model/schedule.ecore</semanticResources>
<semanticResources>platform:/resource/org.fortiss.af3.platform/model/deployment.ecore</semanticResources>
<semanticResources>platform:/resource/org.fortiss.af3.platform/model/deployment.genmodel</semanticResources>
<semanticResources>platform:/resource/org.fortiss.af3.schedule/model/schedule.genmodel</semanticResources>
<ownedViews xmi:type="viewpoint:DView" uid="_0ZbWAEniEei1a5h03EPS7w">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']"/>
......
......@@ -5,7 +5,7 @@
editorDirectory="/org.fortiss.af3.partition.editor/generated-src" modelPluginID="org.fortiss.af3.partition"
modelName="Partition" testsDirectory="/org.fortiss.af3.partition.tests/generated-src"
importerID="org.eclipse.emf.importer.ecore" containmentProxies="true" complianceLevel="8.0"
copyrightFields="false" usedGenPackages="platform:/resource/org.fortiss.af3.platform/model/platform.genmodel#//model platform:/resource/org.fortiss.af3.task/model/task.genmodel#//model platform:/resource/org.fortiss.af3.component/model/component.genmodel#//model platform:/resource/org.fortiss.af3.expression/model/expression.genmodel#//model platform:/resource/org.fortiss.af3.project/model/project.genmodel#//model platform:/resource/org.fortiss.af3.allocation/model/allocation.genmodel#//model platform:/resource/org.fortiss.tooling.base/model/base.genmodel#//model platform:/resource/org.fortiss.tooling.kernel/model/kernel.genmodel#//model platform:/resource/org.fortiss.af3.timing/model/timing.genmodel#//model platform:/resource/org.fortiss.af3.schedule/model/schedule.genmodel#//model platform:/resource/org.fortiss.af3.platform/model/deployment.genmodel#//model">
copyrightFields="false" usedGenPackages="platform:/resource/org.fortiss.af3.platform/model/platform.genmodel#//model platform:/resource/org.fortiss.af3.task/model/task.genmodel#//model platform:/resource/org.fortiss.af3.component/model/component.genmodel#//model platform:/resource/org.fortiss.af3.expression/model/expression.genmodel#//model platform:/resource/org.fortiss.af3.project/model/project.genmodel#//model platform:/resource/org.fortiss.af3.allocation/model/allocation.genmodel#//model platform:/resource/org.fortiss.tooling.base/model/base.genmodel#//model platform:/resource/org.fortiss.tooling.kernel/model/kernel.genmodel#//model platform:/resource/org.fortiss.af3.timing/model/timing.genmodel#//model platform:/resource/org.fortiss.af3.schedule/model/schedule.genmodel#//model">
<foreignModel>partition.ecore</foreignModel>
<genPackages prefix="Partition" basePackage="org.fortiss.af3.partition" disposableProviderFactory="true"
ecorePackage="partition.ecore#/">
......
......@@ -16,16 +16,7 @@ Require-Bundle: org.fortiss.af3.component;visibility:=reexport,
org.fortiss.af3.allocation;visibility:=reexport,
org.fortiss.af3.timing;visibility:=reexport,
com.google.guava;visibility:=reexport
Export-Package: org.fortiss.af3.deployment,
org.fortiss.af3.deployment.migration,
org.fortiss.af3.deployment.model,
org.fortiss.af3.deployment.model.annotation,
org.fortiss.af3.deployment.model.annotation.impl,
org.fortiss.af3.deployment.model.annotation.util,
org.fortiss.af3.deployment.model.impl,
org.fortiss.af3.deployment.model.util,
org.fortiss.af3.deployment.utils,
org.fortiss.af3.platform,
Export-Package: org.fortiss.af3.platform,
org.fortiss.af3.platform.annotation.valueprovider,
org.fortiss.af3.platform.baremetal.generator,
org.fortiss.af3.platform.compose,
......
deployment.ecore 28d5a45bf242f09044f30bf34aee407fc22162db GREEN
platform.ecore 202a4c23ba0c53f29170390ce9a392f5d72139ab GREEN
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText="(c) 2017 fortiss GmbH. GENERATED CODE: Do not edit, see Ecore metamodel instead!"
modelDirectory="/org.fortiss.af3.platform/generated-src" editDirectory="/org.fortiss.af3.platform.edit/generated-src"
editorDirectory="/org.fortiss.af3.platform.editor/generated-src" modelPluginID="org.fortiss.af3.platform"
modelName="Model" modelPluginClass="" editPluginClass="org.fortiss.af3.deployment.model.provider.ModelEditPlugin"
editorPluginClass="org.fortiss.af3.deployment.model.presentation.ModelEditorPlugin"
testsDirectory="/org.fortiss.af3.platform.tests/test-src" importerID="org.eclipse.emf.importer.ecore"
containmentProxies="true" complianceLevel="8.0" copyrightFields="false" language=""
usedGenPackages="platform:/resource/org.fortiss.tooling.base/model/base.genmodel#//model platform:/resource/org.fortiss.af3.component/model/component.genmodel#//model platform:/resource/org.fortiss.af3.expression/model/expression.genmodel#//model platform.genmodel#//model platform:/resource/org.fortiss.af3.project/model/project.genmodel#//model platform:/resource/org.fortiss.af3.timing/model/timing.genmodel#//model platform:/resource/org.fortiss.tooling.kernel/model/kernel.genmodel#//model platform:/resource/org.fortiss.af3.allocation/model/allocation.genmodel#//model">
<foreignModel>deployment.ecore</foreignModel>
<genPackages prefix="AF3Deployment" basePackage="org.fortiss.af3.deployment" disposableProviderFactory="true"
ecorePackage="deployment.ecore#/">
<genEnums typeSafeEnumCompatible="false" ecoreEnum="deployment.ecore#//TrafficType">
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficType/NOT_ASSIGNED"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficType/TIME_TRIGGERED"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficType/RATE_CONSTRAINT"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficType/BEST_EFFORT"/>
</genEnums>
<genEnums typeSafeEnumCompatible="false" ecoreEnum="deployment.ecore#//TrafficDirection">
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficDirection/NOT_ASSIGNED"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficDirection/INPUT"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//TrafficDirection/OUTPUT"/>
</genEnums>
<genEnums typeSafeEnumCompatible="false" ecoreEnum="deployment.ecore#//PortSemantics">
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//PortSemantics/NOT_ASSIGNED"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//PortSemantics/EVENT"/>
<genEnumLiterals ecoreEnumLiteral="deployment.ecore#//PortSemantics/STATE"/>
</genEnums>
<genClasses ecoreClass="deployment.ecore#//Deployment">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/componentArchitectureReference"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/platformArchitectureReference"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/componentAllocations"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/portAllocations"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/deploymentParameterMap"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//Deployment/generatedDeployment"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/route"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//Deployment/transceiverPortAllocation"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//ComponentAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//ComponentAllocation/component"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//ComponentAllocation/executionUnit"/>
</genClasses>
<genClasses image="false" ecoreClass="deployment.ecore#//PortAllocation"/>
<genClasses ecoreClass="deployment.ecore#//InputPortAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//InputPortAllocation/inputPort"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//InputPortAllocation/receiver"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//OutputPortAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//OutputPortAllocation/outputPort"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//OutputPortAllocation/transmitter"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//ComponentArchitectureReference"/>
<genClasses ecoreClass="deployment.ecore#//PlatformArchitectureReference"/>
<genClasses ecoreClass="deployment.ecore#//TransceiverAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverAllocation/port"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverAllocation/transceiver"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverAllocation/transceiverPort"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//TransceiverPortAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverPortAllocation/transceiver"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverPortAllocation/transceiverPort"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//TransceiverPort">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverPort/segment"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//RoutingAllocation">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//RoutingAllocation/virtualLinks"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//VirtualLink">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//VirtualLink/rootSegment"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//Segment">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//Segment/next"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//TransceiverPortSegment">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverPortSegment/transceiverPort"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//TransceiverSegment">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//TransceiverSegment/transceiver"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//DeploymentParameterKey">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//DeploymentParameterKey/hashCode.1"/>
<genOperations ecoreOperation="deployment.ecore#//DeploymentParameterKey/hashCode"
body="return DeploymentParameterKeyStaticImpl.hashCode(this);"/>
<genOperations ecoreOperation="deployment.ecore#//DeploymentParameterKey/equals"
body="return DeploymentParameterKeyStaticImpl.equals(this, other);">
<genParameters ecoreParameter="deployment.ecore#//DeploymentParameterKey/equals/other"/>
</genOperations>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//DeploymentParameterValue">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//DeploymentParameterValue/component"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference deployment.ecore#//DeploymentParameterValue/executionUnit"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//DeploymentParameterKeyToDeploymentParameterValueMap">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//DeploymentParameterKeyToDeploymentParameterValueMap/key"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference deployment.ecore#//DeploymentParameterKeyToDeploymentParameterValueMap/value"/>
</genClasses>
<nestedGenPackages prefix="AF3DeploymentAnnotation" basePackage="org.fortiss.af3.deployment.model"
disposableProviderFactory="true" ecorePackage="deployment.ecore#//annotation">
<genClasses ecoreClass="deployment.ecore#//annotation/TransceiverPortDirection"/>
<genClasses ecoreClass="deployment.ecore#//annotation/TransceiverPortSemantics">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//annotation/TransceiverPortSemantics/semantics"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//annotation/TransceiverPortAccessRights">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference deployment.ecore#//annotation/TransceiverPortAccessRights/admissibleExecutionUnits"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//annotation/VlTrafficType">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//annotation/VlTrafficType/type"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//annotation/VlSender"/>
<genClasses ecoreClass="deployment.ecore#//annotation/VlReceivers"/>
<genClasses ecoreClass="deployment.ecore#//annotation/VlTempRepetition">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//annotation/VlTempRepetition/periodOrMint"/>
</genClasses>
<genClasses ecoreClass="deployment.ecore#//annotation/VlPayloadSize">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute deployment.ecore#//annotation/VlPayloadSize/maxSize"/>
</genClasses>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
......@@ -36,22 +36,6 @@
genModel="model/platform.genmodel"/>
</extension>
<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated deployment -->
<package
uri="http://www.fortiss.org/af3/deployment"
class="org.fortiss.af3.deployment.model.AF3DeploymentPackage"
genModel="model/deployment.genmodel"/>
</extension>
<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated deployment -->
<package
uri="http://www.fortiss.org/af3/deployment/annotation"
class="org.fortiss.af3.deployment.model.annotation.AF3DeploymentAnnotationPackage"
genModel="model/deployment.genmodel"/>
</extension>
<extension point="org.fortiss.tooling.kernel.modelElementConstraintChecker">
<modelElementConstraintChecker checker="org.fortiss.af3.platform.language.constraint.ExecutableGenerationConstraint">
<modelElementClass modelElementClass="org.fortiss.af3.platform.model.PlatformArchitecture"/>
......@@ -217,8 +201,5 @@
<migrationProvider migrationProvider="org.fortiss.af3.platform.model.MemoryPerNodeAnnotationMigrationProvider">
<objectClass objectClass="org.fortiss.af3.platform.model.PlatformArchitecture"/>
</migrationProvider>
<migrationProvider migrationProvider="org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration">
<objectClass objectClass="org.fortiss.af3.deployment.model.Deployment"/>
</migrationProvider>
</extension>
</plugin>
!!! This package is only intended for model migration. Do no change anything inside. !!!
DeploymentMigratorBase.java d93d7de512436d91ec539f0b523279e52885b55f GREEN
DeploymentToAllocationMigration.java df2d2948e72dd6e229221dfd0b0f743c4426bd58 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.deployment.migration;
import static java.util.stream.Collectors.toList;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.getAllocationElement;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.getDeploymentName;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.isDone;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.markAsDone;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.markOthersAsDone;
import static org.fortiss.af3.deployment.migration.DeploymentToAllocationMigration.tryDeleteDeployments;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationTable;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
* Base class for migration providers that replaces {@code Deployment} referenced in another
* submodel.
*
* @author barner
*/
@SuppressWarnings("deprecation")
public abstract class DeploymentMigratorBase<T extends IModelElement>
implements IMigrationProvider {
/** Type of elements to be migrated . */
private Class<T> elementType;
/** Constructor. */
protected DeploymentMigratorBase(Class<T> elementType) {
this.elementType = elementType;
}
/** Returns the {@code Deployment} to be migrated that is referenced by the given element. */
protected abstract Deployment getDeployment(T element);
/** Returns the {@link Stream} of elements that are based on a {@code Deployment}. */
private Stream<T> getElements(EObject rootElement) {
return getChildrenWithType(rootElement, elementType).stream()
.filter(e -> getDeployment(e) != null && !isDone(getDeployment(e), getClass()));
}
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement modelElement,
Map<EObject, AnyType> unknownFeatures) {
List<T> elements = getElements(modelElement.getRootModelElement()).collect(toList());
markOthersAsDone(elements.stream().map(e -> getDeployment(e)).collect(toList()),
getClass());
tryDeleteDeployments();
return !elements.isEmpty();
}
/** Migrates the given {@code element}. */
protected abstract void migrateElement(T element,
ComponentToExecutionUnitAllocationTable ca2hw);
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures) {
getElements(modelElement.getRootModelElement()).forEach(element -> {
Deployment deployment = getDeployment(element);
ComponentToExecutionUnitAllocationTable ca2hw =
getAllocationElement(deployment, ComponentToExecutionUnitAllocationTable.class);
if(ca2hw == null) {
System.err.println("Error in " + getClass().getSimpleName() +
". A model element to be migrated references the deployment \"" +
getDeploymentName(deployment) +
"\" that could not be migrated to a Component-to-ExecutionUnit allocation table.");
return;
}
migrateElement(element, ca2hw);
markAsDone(deployment, getClass());
});
tryDeleteDeployments();
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.deployment.migration;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.eclipse.emf.ecore.util.EcoreUtil.delete;
import static org.fortiss.af3.allocation.utils.AllocationModelElementFactory.createAllocationTableCollection;
import static org.fortiss.af3.allocation.utils.AllocationUtils.addAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getAllocationEntry;
import static org.fortiss.af3.deployment.utils.DeploymentUtils.getComponentArchitecture;
import static org.fortiss.af3.deployment.utils.DeploymentUtils.getPlatformArchitecture;
import static org.fortiss.af3.platform.utils.PlatformModelElementFactory.createComponentToExecutionUnitAllocationTable;
import static org.fortiss.af3.project.utils.ProjectUtils.getFileProject;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.disableNotificationsOf;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.enableNotificationsOf;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.replaceEObjectReferences;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElements;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.fixMissingIDs;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Stream;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTableCollection;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.deployment.model.ComponentAllocation;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.deployment.model.InputPortAllocation;
import org.fortiss.af3.deployment.model.OutputPortAllocation;
import org.fortiss.af3.deployment.model.PortAllocation;
import org.fortiss.af3.deployment.model.TransceiverAllocation;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationEntry;
import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationTable;
import org.fortiss.af3.platform.model.allocation.InputPortToReceiverAllocationEntry;
import org.fortiss.af3.platform.model.allocation.OutputPortToTransmitterAllocationEntry;
import org.fortiss.af3.platform.model.allocation.PortToTransceiverAllocationEntry;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
* Migration Provider from {@link Deployment}s to {@link ComponentToExecutionUnitAllocationTable}s.
*
* @author barner
*/
@SuppressWarnings({"javadoc", "deprecation"})
public class DeploymentToAllocationMigration implements IMigrationProvider {
/**
* Map to track from deployment to allocation model elements (required to migrate models that
* reference {@link Deployment}s.
*/
private static Map<EObject, EObject> depl2allocMap = new HashMap<>();
/**
* {@link Map} that tracks the migrators that have already processed a given {@link Deployment}
* (including migrators that depend on this {@link DeploymentToAllocationMigration}).
*/
private static Map<Deployment, Set<Class<? extends IMigrationProvider>>> migratorMap =
new HashMap<>();
/** Number for migrators that must process a {@link Deployment} before it can be deleted. */
private static final int DEPLOYMENT_MIGRATOR_COUNT = 4;
/** Unicode right arrow. */
public static final String RIGHT_ARROW = "\u2192";
/**
* For the given {@link Deployment} model element, return the corresponding allocation model
* element, or {@code null} in case it could not be found.
*/
public static <T extends EObject> T getAllocationElement(EObject deploymentElement,
Class<T> type) {
T allocationElement = getAllocationElementFromMap(deploymentElement, type);
if(allocationElement != null) {
return allocationElement;
}
// Check if given element is part of a Deployment at all
Deployment deployment = getParentElement(deploymentElement, Deployment.class, true);
if(deployment == null || deployment.eContainer() == null) {
return null;
}
// Check if on-the-fly migration is required and try again
if(needMigration(deployment.eContainer())) {
migrateDeployment(deployment);
allocationElement = getAllocationElementFromMap(deploymentElement, type);
if(allocationElement != null) {
return allocationElement;
}
}
return null;
}
/** Helper for {@link #getAllocationElement(EObject, Class)}. */
@SuppressWarnings("unchecked")
private static <T extends EObject> T getAllocationElementFromMap(EObject deploymentElement,
Class<T> type) {
EObject allocationElement = depl2allocMap.get(deploymentElement);
if(allocationElement != null && type.isAssignableFrom(allocationElement.getClass())) {
return (T)allocationElement;
}
return null;
}
/** Registers a deployment-allocation model element pair. */
private static EObject addDeploymentAllocationModelElementCorrespondance(
EObject deploymentElement, EObject allocationElement) {
return depl2allocMap.put(deploymentElement, allocationElement);
}
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement modelElement,
Map<EObject, AnyType> unknownFeatures) {
return needMigration(modelElement.getRootModelElement());
}
/** Returns the {@link Stream} of {@link Deployment}s to be migrated. */
private static Stream<Deployment> getDeployments(EObject rootModelElement) {
return getRootElements(rootModelElement, Deployment.class).stream()
.filter(d -> !isDone(d, DeploymentToAllocationMigration.class));
}
/**
* Predicate iff the model represented by the given {@code rootModelElement} still has to be
* migrated.
*/
private static boolean needMigration(EObject rootModelElement) {
return getDeployments(rootModelElement).findAny().isPresent();
}
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures) {
getDeployments(modelElement.getRootModelElement()).forEach(deployment -> {
migrateDeployment(deployment);
});
tryDeleteDeployments();
}
/** Migrates a {@link Deployment} */
private static void migrateDeployment(Deployment deployment) {
String deplName = getDeploymentName(deployment);
ComponentArchitecture ca = getComponentArchitecture(deployment);
if(ca == null) {
System.err.println(
"Error migrating " + deplName + ": ca=null. Removing without migration.");
markAsDone(deployment, DeploymentToAllocationMigration.class);
return;
}
PlatformArchitecture pa = getPlatformArchitecture(deployment);
if(pa == null) {
System.err.println(
"Error migrating " + deplName + ": pa=null. Removing without migration.");
markAsDone(deployment, DeploymentToAllocationMigration.class);
return;
}
FileProject fileProject = getFileProject(deployment);
AllocationTableCollection atc =
createAllocationTableCollection("Allocations (migrated from " + deplName + ")");
fileProject.getRootElements().add(atc);
String ca2hwName =
"Components " + RIGHT_ARROW + " Hardware (migrated from " + deplName + ")";
ComponentToExecutionUnitAllocationTable ca2hw =
createComponentToExecutionUnitAllocationTable(ca2hwName, ca, pa);
atc.getContainedElements().add(ca2hw);
addDeploymentAllocationModelElementCorrespondance(deployment, ca2hw);
// Migrate Component -> Execution unit allocations
for(ComponentAllocation caAlloc : deployment.getComponentAllocations()) {
migrateAllocationEntry(ca2hw, ComponentToExecutionUnitAllocationEntry.class, caAlloc,
caAlloc.getComponent(), caAlloc.getExecutionUnit(), deplName);
}
// Migrate port allocations
for(PortAllocation portAlloc : deployment.getPortAllocations()) {
if(portAlloc instanceof InputPortAllocation) {
InputPortAllocation inputPortAlloc = (InputPortAllocation)portAlloc;
migrateAllocationEntry(ca2hw, InputPortToReceiverAllocationEntry.class,
inputPortAlloc, inputPortAlloc.getInputPort(), inputPortAlloc.getReceiver(),
deplName);
} else if(portAlloc instanceof OutputPortAllocation) {
OutputPortAllocation outputPortAlloc = (OutputPortAllocation)portAlloc;
migrateAllocationEntry(ca2hw, OutputPortToTransmitterAllocationEntry.class,
outputPortAlloc, outputPortAlloc.getOutputPort(),
outputPortAlloc.getTransmitter(), deplName);
} else if(portAlloc instanceof TransceiverAllocation) {
TransceiverAllocation transceiverAlloc = (TransceiverAllocation)portAlloc;
migrateAllocationEntry(ca2hw, PortToTransceiverAllocationEntry.class,
transceiverAlloc, transceiverAlloc.getPort(),
transceiverAlloc.getTransceiver(), deplName);
}
}
fixMissingIDs(atc, deployment);
markAsDone(deployment, DeploymentToAllocationMigration.class);
}
/** Determines a non-{@code null} name for the given {@link Deployment}. */
public static String getDeploymentName(Deployment depl) {
return depl.getName() != null ? depl.getName() : "deployment w/ id=" + depl.getId();
}
/**
* Migrates a {@link ComponentAllocation} into a
* {@link ComponentToExecutionUnitAllocationEntry}.
*/
private static void migrateAllocationEntry(ComponentToExecutionUnitAllocationTable ca2hw,
Class<? extends AllocationEntry> entryType, EObject deplObject,
IModelElement sourceElement, IModelElement targetElement, String deplName) {
String errorMsgPrefix = "Error migrating allocation entry of type " +
entryType.getSimpleName() + " for deployment " + deplName + ": ";