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

Introduce container scope.

parent 42b61312
No related branches found
No related tags found
No related merge requests found
......@@ -186,6 +186,7 @@ public class ModelSkeletonAdapter extends AdapterImpl {
if (curFeature instanceof EReference) {
if (((EReference) curFeature).isContainment()) {
Object value = changedObject.eGet(curFeature);
if (value != null) {
if (curFeature.isMany()) {
List<?> children = (List<?>) value;
for (Object curChild : children) {
......@@ -197,6 +198,7 @@ public class ModelSkeletonAdapter extends AdapterImpl {
ModelSkeletonAdapter childAdapter = agent.adapt((EObject) value, ModelSkeletonAdapter.class);
childAdapter.synchronizeTree(Collections.<EStructuralFeature> emptySet());
}
}
}
}
......
......@@ -48,7 +48,6 @@ import edu.kit.ipd.descartes.mm.applicationlevel.system.System;
import edu.kit.ipd.descartes.mm.deployment.Deployment;
import edu.kit.ipd.descartes.mm.deployment.DeploymentFactory;
import edu.kit.ipd.descartes.mm.resourcelandscape.DistributedDataCenter;
import edu.kit.ipd.descartes.mm.resourcelandscape.RuntimeEnvironment;
import edu.kit.ipd.descartes.mm.resourcetype.ResourceTypeRepository;
import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypeFactory;
import tools.descartes.prisma.core.MessageBus;
......@@ -59,7 +58,7 @@ import tools.descartes.prisma.core.agent.AgentController;
import tools.descartes.prisma.model.sensor.Sensor;
import tools.descartes.prisma.model.skeleton.ModelSkeleton;
public class ApplicationScope extends AgentScope {
public class ApplicationScope extends ContainerScope {
public static final String APPLICATION_SCOPE_TYPE = "application";
......@@ -79,10 +78,6 @@ public class ApplicationScope extends AgentScope {
super(name, APPLICATION_SCOPE_TYPE, systemScope, repository, messageBus);
}
public String getRuntimeEnvironmentInputPort() {
return getBasePath() + "." + getName() + ".RuntimeEnvironmentInput";
}
public String getInterfaceExchange() {
return getBasePath() + "." + getName() + ".Interface";
}
......@@ -268,7 +263,6 @@ public class ApplicationScope extends AgentScope {
protected void createMessageExchanges() {
super.createMessageExchanges();
declareNotification(new NotificationDefinition(RuntimeEnvironment.class, getRuntimeEnvironmentInputPort()));
declareNotification(new NotificationDefinition(Interface.class, getInterfaceExchange()));
declareNotification(
new NotificationDefinition(BasicComponent.class, getBasicComponentExchange()));
......
/**
* ==============================================
* LibReDE : Library for Resource Demand Estimation
* ==============================================
*
* (c) Copyright 2013-2014, by Simon Spinner and Contributors.
*
* Project Info: http://www.descartes-research.net/
*
* All rights reserved. This software is made available under the terms of the
* Eclipse Public License (EPL) v1.0 as published by the Eclipse Foundation
* http://www.eclipse.org/legal/epl-v10.html
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License (EPL)
* for more details.
*
* You should have received a copy of the Eclipse Public License (EPL)
* along with this software; if not visit http://www.eclipse.org or write to
* Eclipse Foundation, Inc., 308 SW First Avenue, Suite 110, Portland, 97204 USA
* Email: license (at) eclipse.org
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*/
package tools.descartes.prisma.core.scopes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import edu.kit.ipd.descartes.mm.resourcelandscape.Container;
import tools.descartes.prisma.core.MessageBus;
import tools.descartes.prisma.core.ModelRepository;
import tools.descartes.prisma.core.Transaction;
import tools.descartes.prisma.core.adapter.ModelSkeletonAdapter;
import tools.descartes.prisma.core.adapter.ObjectMatcher;
import tools.descartes.prisma.core.agent.AgentController;
import tools.descartes.prisma.core.exceptions.CommitException;
import tools.descartes.prisma.model.skeleton.ModelSkeleton;
public abstract class ContainerScope extends AgentScope {
private static final String CONTAINER_SUFFIX = ".container";
private List<Container> containers;
public ContainerScope(String name, String type, SystemGlobalScope systemScope, ModelRepository repository,
MessageBus messageBus) {
super(name, type, systemScope, repository, messageBus);
}
public String getRuntimeEnvironmentInputPort() {
return getBasePath() + "." + getName() + ".RuntimeEnvironmentInput";
}
@Override
public void registerElement(EObject element) {
super.registerElement(element);
if (element instanceof Container) {
Container newContainer = (Container) element;
// Check that this object is not already save as container in this
// scope.
for (Container curContainer : getContainer()) {
if (ObjectMatcher.matches(curContainer, newContainer)) {
return;
}
}
// Save it in a separate resource.
try (Transaction curTransaction = getModelRepository().createTransaction()) {
Resource res = getModelRepository().getOrCreateResource(curTransaction,
getContainerPath(newContainer.getName()));
res.getContents().add(curTransaction.attach(newContainer));
curTransaction.commit();
} catch (CommitException e) {
e.printStackTrace();
}
}
}
@Override
public void deregisterElement(EObject element) {
if (element instanceof Container) {
Container obsoleteContainer = (Container) element;
// Check that this object is not already save as container in this
// scope.
for (Container curContainer : getContainer()) {
if (ObjectMatcher.matches(curContainer, obsoleteContainer)) {
// Remove resource
try (Transaction curTransaction = getModelRepository().createTransaction()) {
CDOResource resource = curTransaction.attach(obsoleteContainer).cdoDirectResource();
resource.delete(Collections.emptyMap());
curTransaction.commit();
} catch (CommitException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public List<Container> getContainer() {
if (containers == null) {
containers = new ArrayList<>();
List<String> resources = getModelRepository().listResources(getBasePath() + "/" + getName());
for (String curPath : resources) {
if (curPath.endsWith(CONTAINER_SUFFIX)) {
EObject obj = getModelRepository().getResource(getBasePath() + "/" + getName() + "/" + curPath)
.getContents().get(0);
containers.add((Container) obj);
}
}
}
return containers;
}
private String getContainerPath(String containerName) {
return getBasePath() + "/" + getName() + "/" + containerName + CONTAINER_SUFFIX;
}
@Override
protected List<ModelSkeletonAdapter> synchronizeModelSkeletonTree(AgentController agent, Transaction transaction, ModelSkeleton skeleton) {
List<ModelSkeletonAdapter> synchronizedAdapters = super.synchronizeModelSkeletonTree(agent, transaction,
skeleton);
for (Container curContainer : skeleton.getContainers()) {
for (Container curRepoContainer : getContainer()) {
if (ObjectMatcher.matches(curContainer, curRepoContainer)) {
synchronizeModelRoot(agent, transaction, curContainer, curRepoContainer, synchronizedAdapters);
break;
}
}
}
return synchronizedAdapters;
}
@Override
protected void createMessageExchanges() {
super.createMessageExchanges();
declareInputPort(getRuntimeEnvironmentInputPort());
}
}
......@@ -26,45 +26,26 @@
*/
package tools.descartes.prisma.core.scopes;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import edu.kit.ipd.descartes.mm.resourcelandscape.Container;
import edu.kit.ipd.descartes.mm.resourcelandscape.RuntimeEnvironment;
import edu.kit.ipd.descartes.mm.runtimeenvironmentclasses.RuntimeEnvironmentClasses;
import tools.descartes.prisma.core.MessageBus;
import tools.descartes.prisma.core.ModelRepository;
import tools.descartes.prisma.core.Transaction;
import tools.descartes.prisma.core.adapter.ModelSkeletonAdapter;
import tools.descartes.prisma.core.adapter.ObjectMatcher;
import tools.descartes.prisma.core.agent.AgentController;
import tools.descartes.prisma.core.exceptions.CommitException;
import tools.descartes.prisma.model.sensor.Sensor;
import tools.descartes.prisma.model.skeleton.ModelSkeleton;
public class PlatformScope extends AgentScope {
private static final String CONTAINER_SUFFIX = ".container";
public class PlatformScope extends ContainerScope {
public static final String VIRTUAL_INFRASTRUCTURE_SCOPE_TYPE = "virtual";
public static final String PLATFORM_SCOPE_TYPE = "platform";
private List<Container> containers;
public PlatformScope(String name, String type, SystemGlobalScope systemScope,
ModelRepository repository,
MessageBus messageBus) {
super(name, type, systemScope, repository, messageBus);
}
public String getRuntimeEnvironmentInputPort() {
return getBasePath() + "." + getName() + ".RuntimeEnvironmentInput";
}
public String getRuntimeEnvironmentOutputPort() {
return getBasePath() + "." + getName() + ".RuntimeEnvironmentOutput";
}
......@@ -101,80 +82,6 @@ public class PlatformScope extends AgentScope {
return ((Sensor<?>) o).getMetric().getId();
}
});
declareInputPort(getRuntimeEnvironmentInputPort());
declareStatisticsPort(getRuntimeEnvironmentStatisticsOutputPort());
}
@Override
public void registerElement(EObject element) {
super.registerElement(element);
if (element instanceof Container) {
Container newContainer = (Container) element;
// Check that this object is not already save as container in this
// scope.
for (Container curContainer : getContainer()) {
if (ObjectMatcher.matches(curContainer, newContainer)) {
return;
}
}
// Save it in a separate resource.
try (Transaction curTransaction = getModelRepository().createTransaction()) {
Resource res = getModelRepository().getOrCreateResource(curTransaction,
getContainerPath(newContainer.getName()));
res.getContents().add(curTransaction.attach(newContainer));
curTransaction.commit();
} catch (CommitException e) {
e.printStackTrace();
}
}
}
public List<Container> getContainer() {
if (containers == null) {
containers = new ArrayList<>();
List<String> resources = getModelRepository().listResources(getBasePath() + "/" + getName());
for (String curPath : resources) {
if (curPath.endsWith(CONTAINER_SUFFIX)) {
EObject obj = getModelRepository().getResource(getBasePath() + "/" + getName() + "/" + curPath)
.getContents().get(0);
containers.add((Container) obj);
}
}
}
return containers;
}
private String getContainerPath(String containerName) {
return getBasePath() + "/" + getName() + "/" + containerName + CONTAINER_SUFFIX;
}
@Override
protected void createResources(Transaction transaction) {
super.createResources(transaction);
// Create the resource.
// The containers may be added later
}
@Override
protected List<ModelSkeletonAdapter> synchronizeModelSkeletonTree(AgentController agent, Transaction transaction, ModelSkeleton skeleton) {
List<ModelSkeletonAdapter> synchronizedAdapters = super.synchronizeModelSkeletonTree(agent, transaction,
skeleton);
for (Container curContainer : skeleton.getContainers()) {
for (Container curRepoContainer : getContainer()) {
if (ObjectMatcher.matches(curContainer, curRepoContainer)) {
synchronizeModelRoot(agent, transaction, curContainer, curRepoContainer, synchronizedAdapters);
break;
}
}
}
return synchronizedAdapters;
}
}
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