use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelProvider method updateComponent.
/*
* (non-Javadoc)
*
* @see org.iobserve.analysis.modelneo4j.IModelProvider#updateComponent(java.lang.Class, T)
*/
@Override
public void updateComponent(final Class<T> clazz, final T component) {
ModelProviderSynchronizer.getLock(this);
final EAttribute idAttr = component.eClass().getEIDAttribute();
final Label label = Label.label(clazz.getSimpleName());
final Set<EObject> containmentsAndDatatypes;
final Node node;
if (idAttr != null) {
try (Transaction tx = this.graph.getGraphDatabaseService().beginTx()) {
node = this.graph.getGraphDatabaseService().findNode(label, ModelProvider.ID, component.eGet(idAttr));
containmentsAndDatatypes = this.getAllContainmentsAndDatatypes(component, new HashSet<>());
this.updateNodes(component, node, containmentsAndDatatypes, new HashSet<EObject>());
tx.success();
}
} else if (component instanceof ResourceEnvironment || component instanceof UsageModel) {
try (Transaction tx = this.graph.getGraphDatabaseService().beginTx()) {
final ResourceIterator<Node> nodes = this.graph.getGraphDatabaseService().findNodes(Label.label(clazz.getSimpleName()));
if (nodes.hasNext()) {
node = nodes.next();
containmentsAndDatatypes = this.getAllContainmentsAndDatatypes(component, new HashSet<>());
this.updateNodes(component, node, containmentsAndDatatypes, new HashSet<EObject>());
}
tx.success();
}
} else {
if (ModelProvider.LOGGER.isWarnEnabled()) {
ModelProvider.LOGGER.warn("Updated component needs to have an id or be of type Allocation, Repository, " + "ResourceEnvironment, System or UsageModel");
}
}
ModelProviderSynchronizer.releaseLock(this);
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelProvider method readOnlyRootComponent.
/**
* Reads the pcm models root components Allocation, Repository, ResourceEnvironment, System or
* UsageModel without locking the graph for other providers.
*
* @param clazz
* Data type of the root component
* @return The read component
*/
@Override
@SuppressWarnings("unchecked")
public T readOnlyRootComponent(final Class<T> clazz) {
EObject component = null;
try (Transaction tx = this.graph.getGraphDatabaseService().beginTx()) {
if (clazz.equals(Allocation.class) || clazz.equals(Repository.class) || clazz.equals(ResourceEnvironment.class) || clazz.equals(System.class) || clazz.equals(UsageModel.class)) {
final ResourceIterator<Node> nodes = this.graph.getGraphDatabaseService().findNodes(Label.label(clazz.getSimpleName()));
if (nodes.hasNext()) {
final Node node = nodes.next();
final Set<Node> containmentsAndDatatypes = this.getAllContainmentsAndDatatypes(node, new HashSet<Node>());
component = this.readNodes(node, containmentsAndDatatypes, new HashMap<Node, EObject>());
}
} else {
ModelProvider.LOGGER.warn("Passed type of readRootComponent(final Class<T> clazz) has to be one of Allocation, Repository, ResourceEnvironment, System or UsageModel!");
}
tx.success();
}
return (T) component;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelHelper method getResourceContainerFromHostname.
/**
* Creates a cloud container from the given hostname with the information provided by the model
* providers in the resource environment provided by the model providers.
*
* If the hostname is not a valid cloud container hostname or if no matching VMType could be
* found, the method returns null.
*
* @param modelProviders
* the model providers to use
* @param hostname
* the hostname to convert
* @return the new cloud container or null in case of a problem
* @throws ModelHandlingErrorException
* modeling handlign issue
*/
public static ResourceContainerCloud getResourceContainerFromHostname(final PCMModelHandler modelProviders, final String hostname) throws ModelHandlingErrorException {
final String[] nameParts = hostname.split("_");
VMType vmType = null;
// ContainerId_AllocationGroupName_ProviderName_Location_InstanceType
if (nameParts.length == 5) {
final String groupName = nameParts[1];
final String providerName = nameParts[2];
final String location = nameParts[3];
final String instanceType = nameParts[4];
vmType = ModelHelper.getVMType(modelProviders.getCloudProfileModel(), providerName, location, instanceType);
if (vmType != null) {
final ResourceEnvironment environment = modelProviders.getResourceEnvironmentModel();
final CostRepository costRepository = modelProviders.getCostModel();
final ResourceContainerCloud cloudContainer = ModelHelper.createResourceContainerFromVMType(environment, costRepository, vmType, hostname);
cloudContainer.setGroupName(groupName);
return cloudContainer;
}
}
return null;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelHelper method fillResourceEnvironmentFromCloudProfile.
/**
* Creates resource containers and their associated costs from the cloud profile given in the
* model provider.
*
* The created resource containers are of the type {@link ResourceContainerCloud} and are
* connected via an Internet linking resource
* ({@link #getInternetLinkingResource(ResourceEnvironment)}. For every vm type in the cloud
* profile, this method creates one resource container representing an instance of this specific
* vm type. The model is saved after the creation of containers is completed.
*
* @param writeURI
* location where all files are stored
* @param modelHandler
* the model providers with an initialized resource environment, cost model and cloud
* profile
* @throws ModelHandlingErrorException
* model handling issue
*/
public static void fillResourceEnvironmentFromCloudProfile(final org.eclipse.emf.common.util.URI writeURI, final PCMModelHandler modelHandler) throws ModelHandlingErrorException {
final ResourceEnvironment environment = modelHandler.getResourceEnvironmentModel();
final CloudProfile cloudProfileModel = modelHandler.getCloudProfileModel();
final CostRepository costRepositoryModel = modelHandler.getCostModel();
for (final CloudProvider provider : cloudProfileModel.getCloudProviders()) {
for (final CloudResourceType cloudResource : provider.getCloudResources()) {
if (cloudResource instanceof VMType) {
final VMType cloudVM = (VMType) cloudResource;
ModelHelper.createResourceContainerFromVMType(environment, costRepositoryModel, cloudVM, cloudVM.getName());
}
}
}
new ResourceEnvironmentModelHandler().save(writeURI.appendFileExtension(PCMModelHandler.RESOURCE_ENVIRONMENT_SUFFIX), environment);
new CostModelHandler().save(writeURI.appendFileExtension(PCMModelHandler.COST_SUFFIX), costRepositoryModel);
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelHelper method fillResourceEnvironmentFromCloudProfile.
/**
* Creates resource containers and their associated costs from the cloud profile given in the
* model provider.
*
* The created resource containers are of the type {@link ResourceContainerCloud} and are
* connected via an Internet linking resource
* ({@link #getInternetLinkingResource(ResourceEnvironment)}. For every vm type in the cloud
* profile, this method creates one resource container representing an instance of this specific
* vm type. The model is saved after the creation of containers is completed.
*
* @param writeURI
* location where all files are stored
* @param modelHandler
* the model providers with an initialized resource environment, cost model and cloud
* profile
* @throws ModelHandlingErrorException
* model handling error
*/
public static void fillResourceEnvironmentFromCloudProfile(final org.eclipse.emf.common.util.URI writeURI, final PCMModelHandler modelHandler) throws ModelHandlingErrorException {
final ResourceEnvironment environment = modelHandler.getResourceEnvironmentModel();
final CloudProfile cloudProfileModel = modelHandler.getCloudProfileModel();
final CostRepository costRepositoryModel = modelHandler.getCostModel();
for (final CloudProvider provider : cloudProfileModel.getCloudProviders()) {
for (final CloudResourceType cloudResource : provider.getCloudResources()) {
if (cloudResource instanceof VMType) {
final VMType cloudVM = (VMType) cloudResource;
ModelHelper.createResourceContainerFromVMType(environment, costRepositoryModel, cloudVM, cloudVM.getName());
}
}
}
new ResourceEnvironmentModelHandler().save(writeURI.appendFileExtension(PCMModelHandler.RESOURCE_ENVIRONMENT_SUFFIX), environment);
new CostModelHandler().save(writeURI.appendFileExtension(PCMModelHandler.COST_SUFFIX), costRepositoryModel);
}
Aggregations