Skip to content
Snippets Groups Projects
Commit 6ae98e4d authored by Simon Spinner's avatar Simon Spinner
Browse files

Add container template

parent f5b6f2d8
No related branches found
No related tags found
No related merge requests found
Showing
with 149 additions and 123 deletions
......@@ -12,7 +12,15 @@ Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.10.2",
org.eclipse.emf.ecore.xmi;bundle-version="2.10.2",
edu.kit.ipd.descartes.mm.applicationlevel.library;bundle-version="1.1.0",
com.google.guava
Export-Package: tools.descartes.prisma.core
Export-Package: tools.descartes.prisma.core,
tools.descartes.prisma.core.templates,
tools.descartes.prisma.core.templates.deployment,
tools.descartes.prisma.core.templates.repository,
tools.descartes.prisma.core.templates.resourceconfiguration,
tools.descartes.prisma.core.templates.resourcelandscape,
tools.descartes.prisma.core.templates.resourcetype,
tools.descartes.prisma.core.templates.servicebehavior,
tools.descartes.prisma.core.templates.system
Import-Package: org.eclipse.emf.cdo.net4j,
org.eclipse.net4j,
org.eclipse.net4j.connector,
......
package tools.descartes.prisma.core.templates.resourceconfiguration;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.kit.ipd.descartes.mm.resourceconfiguration.ActiveResourceSpecification;
import edu.kit.ipd.descartes.mm.resourceconfiguration.ResourceconfigurationFactory;
import edu.kit.ipd.descartes.mm.resourceconfiguration.SchedulingPolicy;
import edu.kit.ipd.descartes.mm.resourcelandscape.Container;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
import tools.descartes.prisma.core.templates.resourcetype.ProcessingResourceTypeTemplate;
public class ActiveResourceSpecificationTemplate extends ModelTemplate<Container, ActiveResourceSpecification> {
public class ActiveResourceSpecificationTemplate extends NamedElementTemplate<Container, ActiveResourceSpecification> {
private final List<ProcessingResourceSpecificationTemplate> processingResources = new LinkedList<>();
private final Map<String, ProcessingResourceSpecificationTemplate> processingResources = new HashMap<>();
public ActiveResourceSpecificationTemplate() {
super(ResourcelandscapePackage.Literals.CONTAINER__CONFIG_SPEC, ActiveResourceSpecification.class);
public ActiveResourceSpecificationTemplate(String name) {
super(ResourcelandscapePackage.Literals.CONTAINER__CONFIG_SPEC, ActiveResourceSpecification.class, name);
}
public ActiveResourceSpecificationTemplate add(ProcessingResourceSpecificationTemplate processingResource) {
processingResources.add(processingResource);
return this;
public ProcessingResourceSpecificationTemplate defineProcessingResource(String name, ProcessingResourceTypeTemplate typeTemplate, SchedulingPolicy policy, int units) {
ProcessingResourceSpecificationTemplate template = processingResources.get(name);
if (template == null) {
template = new ProcessingResourceSpecificationTemplate(name, typeTemplate, policy, units);
processingResources.put(name, template);
}
return template;
}
@Override
public List<? extends ModelTemplate<? super ActiveResourceSpecification, ?>> getChildCommands() {
return processingResources;
}
@Override
public boolean matches(ActiveResourceSpecification object) {
// we only support one of this type
return true;
return new ArrayList<>(processingResources.values());
}
@Override
protected ActiveResourceSpecification create(Container parent) {
ActiveResourceSpecification spec = ResourceconfigurationFactory.eINSTANCE.createActiveResourceSpecification();
spec.setName("active-resources");
spec.setName(getName());
return spec;
}
......
......@@ -6,37 +6,30 @@ import edu.kit.ipd.descartes.mm.resourceconfiguration.ProcessingResourceSpecific
import edu.kit.ipd.descartes.mm.resourceconfiguration.ResourceconfigurationFactory;
import edu.kit.ipd.descartes.mm.resourceconfiguration.ResourceconfigurationPackage;
import edu.kit.ipd.descartes.mm.resourceconfiguration.SchedulingPolicy;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
import tools.descartes.prisma.core.templates.resourcetype.ProcessingResourceTypeTemplate;
public class ProcessingResourceSpecificationTemplate extends ModelTemplate<ActiveResourceSpecification, ProcessingResourceSpecification> {
public class ProcessingResourceSpecificationTemplate extends NamedElementTemplate<ActiveResourceSpecification, ProcessingResourceSpecification> {
private final String name;
private final ProcessingResourceTypeTemplate typeTemplate;
private final SchedulingPolicy policy;
private final int units;
public ProcessingResourceSpecificationTemplate(String name, ProcessingResourceTypeTemplate typeTemplate, SchedulingPolicy policy, int units) {
super(ResourceconfigurationPackage.Literals.ACTIVE_RESOURCE_SPECIFICATION__PROCESSING_RESOURCE_SPECIFICATIONS, ProcessingResourceSpecification.class);
this.name = name;
super(ResourceconfigurationPackage.Literals.ACTIVE_RESOURCE_SPECIFICATION__PROCESSING_RESOURCE_SPECIFICATIONS, ProcessingResourceSpecification.class, name);
this.typeTemplate = typeTemplate;
this.policy = policy;
this.units = units;
}
@Override
public boolean matches(ProcessingResourceSpecification object) {
return name.equals(object.getName());
}
@Override
protected ProcessingResourceSpecification create(ActiveResourceSpecification parent) {
ProcessingResourceSpecification res = ResourceconfigurationFactory.eINSTANCE.createProcessingResourceSpecification();
res.setName(name);
res.setName(getName());
res.setActiveResourceType(typeTemplate.get(getContext().getResourceTypeRepository()));
res.setSchedulingPolicy(policy);
NumberOfParallelProcessingUnits n = ResourceconfigurationFactory.eINSTANCE.createNumberOfParallelProcessingUnits();
n.setName(name);
n.setName(getName());
n.setNumber(units);
res.setNrOfParProcUnits(n);
return res;
......
package tools.descartes.prisma.core.templates.resourcelandscape;
import java.util.LinkedList;
import java.util.List;
import edu.kit.ipd.descartes.mm.resourcelandscape.ComputingInfrastructure;
import edu.kit.ipd.descartes.mm.resourcelandscape.DataCenter;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapeFactory;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
import tools.descartes.prisma.core.templates.resourceconfiguration.ActiveResourceSpecificationTemplate;
public class ComputingInfrastructureTemplate extends NamedElementTemplate<DataCenter, ComputingInfrastructure> {
private final List<ActiveResourceSpecificationTemplate> resources = new LinkedList<>();
public class ComputingInfrastructureTemplate extends ContainerTemplate<DataCenter, ComputingInfrastructure> {
public ComputingInfrastructureTemplate(String name) {
super(ResourcelandscapePackage.Literals.DATA_CENTER__CONTAINS, ComputingInfrastructure.class, name);
}
@Override
public List<? extends ModelTemplate<? super ComputingInfrastructure, ?>> getChildCommands() {
return resources;
}
public ComputingInfrastructureTemplate add(ActiveResourceSpecificationTemplate activeResources) {
resources.add(activeResources);
return this;
}
@Override
protected ComputingInfrastructure create(DataCenter parent) {
ComputingInfrastructure hw = ResourcelandscapeFactory.eINSTANCE.createComputingInfrastructure();
......
package tools.descartes.prisma.core.templates.resourcelandscape;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import edu.kit.ipd.descartes.mm.resourcelandscape.Container;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
import tools.descartes.prisma.core.templates.resourceconfiguration.ActiveResourceSpecificationTemplate;
public abstract class ContainerTemplate<P extends EObject, E extends Container> extends NamedElementTemplate<P, E> {
private final Map<String, ContainerTemplate<E, ?>> containedContainers = new HashMap<>();
private final Map<String, ActiveResourceSpecificationTemplate> resources = new HashMap<>();
public ContainerTemplate(EStructuralFeature container, Class<E> elementType, String name) {
super(container, elementType, name);
}
@Override
public List<? extends ModelTemplate<? super E, ?>> getChildCommands() {
List<ModelTemplate<? super E, ?>> children = new ArrayList<>();
children.addAll(containedContainers.values());
children.addAll(resources.values());
return children;
}
public ActiveResourceSpecificationTemplate defineActiveResource(String name) {
ActiveResourceSpecificationTemplate template = resources.get(name);
if (template == null) {
template = new ActiveResourceSpecificationTemplate(name);
resources.put(name, template);
}
return template;
}
}
package tools.descartes.prisma.core.templates.resourcelandscape;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.kit.ipd.descartes.mm.resourcelandscape.DataCenter;
import edu.kit.ipd.descartes.mm.resourcelandscape.DistributedDataCenter;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapeFactory;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
public class DataCenterTemplate extends ModelTemplate<DistributedDataCenter, DataCenter> {
public class DataCenterTemplate extends NamedElementTemplate<DistributedDataCenter, DataCenter> {
private final String name;
private final List<ComputingInfrastructureTemplate> computingInfrastructure = new LinkedList<>();
private final Map<String, ComputingInfrastructureTemplate> computingInfrastructure = new HashMap<>();
public DataCenterTemplate(String name) {
super(ResourcelandscapePackage.Literals.DISTRIBUTED_DATA_CENTER__CONSISTS_OF, DataCenter.class);
this.name = name;
super(ResourcelandscapePackage.Literals.DISTRIBUTED_DATA_CENTER__CONSISTS_OF, DataCenter.class, name);
}
public DataCenterTemplate add(ComputingInfrastructureTemplate c) {
computingInfrastructure.add(c);
return this;
public ComputingInfrastructureTemplate defineComputingInfrastructure(String name) {
ComputingInfrastructureTemplate template = computingInfrastructure.get(name);
if (template == null) {
template = new ComputingInfrastructureTemplate(name);
computingInfrastructure.put(name, template);
}
return template;
}
@Override
public List<? extends ModelTemplate<? super DataCenter, ?>> getChildCommands() {
return computingInfrastructure;
}
@Override
public boolean matches(DataCenter object) {
if (object != null) {
return name.equals(object.getName());
}
return false;
return new ArrayList<>(computingInfrastructure.values());
}
@Override
protected DataCenter create(DistributedDataCenter parent) {
DataCenter dc = ResourcelandscapeFactory.eINSTANCE.createDataCenter();
dc.setName(name);
dc.setName(getName());
return dc;
}
......
......@@ -4,26 +4,18 @@ import edu.kit.ipd.descartes.mm.resourcetype.ProcessingResourceType;
import edu.kit.ipd.descartes.mm.resourcetype.ResourceTypeRepository;
import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypeFactory;
import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypePackage;
import tools.descartes.prisma.core.templates.ModelTemplate;
import tools.descartes.prisma.core.templates.core.NamedElementTemplate;
public class ProcessingResourceTypeTemplate extends ModelTemplate<ResourceTypeRepository, ProcessingResourceType> {
private final String name;
public class ProcessingResourceTypeTemplate extends NamedElementTemplate<ResourceTypeRepository, ProcessingResourceType> {
public ProcessingResourceTypeTemplate(String name) {
super(ResourcetypePackage.Literals.RESOURCE_TYPE_REPOSITORY__RESOURCE_TYPES, ProcessingResourceType.class);
this.name = name;
}
@Override
public boolean matches(ProcessingResourceType object) {
return object.getName().equals(name);
super(ResourcetypePackage.Literals.RESOURCE_TYPE_REPOSITORY__RESOURCE_TYPES, ProcessingResourceType.class, name);
}
@Override
protected ProcessingResourceType create(ResourceTypeRepository parent) {
ProcessingResourceType type = ResourcetypeFactory.eINSTANCE.createProcessingResourceType();
type.setName(name);
type.setName(getName());
return type;
}
......
package tools.descartes.prisma.core.templates.resourcetype;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.kit.ipd.descartes.mm.resourcetype.ResourceTypeRepository;
import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypeFactory;
......@@ -9,7 +11,7 @@ import tools.descartes.prisma.core.templates.ModelTemplate;
public class ResourceTypeRepositoryTemplate extends ModelTemplate<ResourceTypeRepository, ResourceTypeRepository> {
private final List<ProcessingResourceTypeTemplate> processingResources = new LinkedList<>();
private final Map<String, ProcessingResourceTypeTemplate> processingResources = new HashMap<>();
public ResourceTypeRepositoryTemplate() {
super(null, ResourceTypeRepository.class);
......@@ -27,7 +29,7 @@ public class ResourceTypeRepositoryTemplate extends ModelTemplate<ResourceTypeRe
@Override
public List<? extends ModelTemplate<? super ResourceTypeRepository, ?>> getChildCommands() {
return processingResources;
return new ArrayList<>(processingResources.values());
}
@Override
......@@ -40,8 +42,13 @@ public class ResourceTypeRepositoryTemplate extends ModelTemplate<ResourceTypeRe
return ResourcetypeFactory.eINSTANCE.createResourceTypeRepository();
}
public void add(ProcessingResourceTypeTemplate processingResource) {
processingResources.add(processingResource);
public ProcessingResourceTypeTemplate defineProcessingResource(String name) {
ProcessingResourceTypeTemplate template = processingResources.get(name);
if (template == null) {
template = new ProcessingResourceTypeTemplate(name);
processingResources.put(name, template);
}
return template;
}
}
package tools.descartes.prisma.core.templates.servicebehavior;
import java.util.ArrayList;
import java.util.List;
import edu.kit.ipd.descartes.mm.applicationlevel.parameterdependencies.ModelVariableCharacterizationType;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.AbstractAction;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.BranchAction;
......@@ -31,21 +34,40 @@ public abstract class AbstractActionTemplate<E extends AbstractAction> extends M
}
// 2. Determine the start point from which we begin with the search
AbstractAction current = getCurrentPositionInBehavior(parent);
// 3. The position is behind an existing action at the end of a call path
if (current == null) {
return null;
// search from the beginning
ComponentInternalBehavior currentBehavior = parent;
int positionInBehavior = 0;
if (predecessor != null) {
AbstractAction predecessorAction = predecessor.get(parent);
if (predecessorAction != null) {
currentBehavior = predecessorAction.getParentBehavior();
int idx = currentBehavior.getActions().indexOf(predecessorAction);
if ((idx + 1) < currentBehavior.getActions().size()) {
positionInBehavior = idx + 1;
} else {
// the new action is appended behind the predecessor
if (getStatus() == Status.CREATE) {
E newAction = create(currentBehavior);
currentBehavior.getActions().add(newAction);
return newAction;
} else {
return null;
}
}
}
}
ComponentInternalBehavior currentBehavior = current.getParentBehavior();
if (current instanceof BranchAction) {
BranchAction branch = (BranchAction)current;
// 4. insert into existing behavior
AbstractAction insertionPlace = currentBehavior.getActions().get(positionInBehavior);
if (insertionPlace instanceof BranchAction) {
BranchAction branch = (BranchAction)insertionPlace;
// The branch actions are automatically inserted
// if there alternative call paths were monitored.
// In this case we need to check whether there is
// a already a branch with this action as first entry
for (ComponentInternalBehavior branchBehavior : branch.getBranches()) {
if (!branchBehavior.getActions().isEmpty()) {
E matchedAction = matchesWithCast(branchBehavior);
E matchedAction = matchesWithCast(branchBehavior.getActions().get(0));
if (matchedAction != null) {
return matchedAction;
}
......@@ -63,13 +85,13 @@ public abstract class AbstractActionTemplate<E extends AbstractAction> extends M
// Check the current action for a match
// If the two do not match we need to introduce a
// branch at the current position.
E existingAction = this.matchesWithCast(current);
E existingAction = this.matchesWithCast(insertionPlace);
if (existingAction != null) {
return existingAction;
} else if (getStatus() == Status.CREATE) {
// The two actions are conflicting --> introduce a new branch
E newAction = create(parent);
BranchAction currentBranchAction = insertNewBranchingAction(currentBehavior);
BranchAction currentBranchAction = insertNewBranchingAction(currentBehavior, positionInBehavior);
ComponentInternalBehavior newBranchBehavior = ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior();
newBranchBehavior.getActions().add(newAction);
currentBranchAction.getBranches().add(newBranchBehavior);
......@@ -84,44 +106,24 @@ public abstract class AbstractActionTemplate<E extends AbstractAction> extends M
this.predecessor = predecessor;
}
private BranchAction insertNewBranchingAction(ComponentInternalBehavior parent) {
private BranchAction insertNewBranchingAction(ComponentInternalBehavior parent, int positionInBehavior) {
BranchAction newBranchAction = ServicebehaviorFactory.eINSTANCE.createBranchAction();
BranchProbabilities probabilities = ServicebehaviorFactory.eINSTANCE.createBranchProbabilities();
probabilities.setCharacterization(ModelVariableCharacterizationType.EMPIRICAL);
newBranchAction.setBranchProbabilities(probabilities);
ComponentInternalBehavior existingBranchBehavior = ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior();
existingBranchBehavior.getActions().addAll(parent.getActions());
parent.getActions().clear();
int numActions = parent.getActions().size() - positionInBehavior;
List<AbstractAction> movedActions = new ArrayList<>(numActions);
for (int i = 0; i < numActions; i++) {
movedActions.add(parent.getActions().get(positionInBehavior + i));
}
parent.getActions().removeAll(movedActions);
ComponentInternalBehavior existingBranchBehavior = ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior();
existingBranchBehavior.getActions().addAll(movedActions);
newBranchAction.getBranches().add(existingBranchBehavior);
parent.getActions().add(newBranchAction);
return newBranchAction;
}
private AbstractAction getCurrentPositionInBehavior(ComponentInternalBehavior parent) {
ComponentInternalBehavior currentBehavior = parent;
if (predecessor != null) {
AbstractAction predecessorAction = predecessor.get(parent);
if (predecessorAction != null) {
currentBehavior = predecessorAction.getParentBehavior();
int idx = currentBehavior.getActions().indexOf(predecessorAction);
if ((idx + 1) < currentBehavior.getActions().size()) {
return currentBehavior.getActions().get(idx + 1);
} else {
// the new action is appended behind the predecessor
if (getStatus() == Status.CREATE) {
E newAction = create(parent);
currentBehavior.getActions().add(newAction);
return newAction;
} else {
return null;
}
}
}
}
// by default start at the beginning
return parent.getActions().get(0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment