Search in sources :

Example 31 with ResourceEnvironment

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);
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Transaction(org.neo4j.graphdb.Transaction) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) EObject(org.eclipse.emf.ecore.EObject) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) ResourceIterator(org.neo4j.graphdb.ResourceIterator) HashSet(java.util.HashSet)

Example 32 with ResourceEnvironment

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;
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) EObject(org.eclipse.emf.ecore.EObject) Node(org.neo4j.graphdb.Node)

Example 33 with ResourceEnvironment

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;
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) VMType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType) ResourceContainerCloud(org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud) CostRepository(de.uka.ipd.sdq.pcm.cost.CostRepository)

Example 34 with ResourceEnvironment

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);
}
Also used : CloudProfile(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProfile) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) CloudResourceType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudResourceType) VMType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType) CostRepository(de.uka.ipd.sdq.pcm.cost.CostRepository) CostModelHandler(org.iobserve.model.provider.file.CostModelHandler) CloudProvider(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProvider) ResourceEnvironmentModelHandler(org.iobserve.model.provider.file.ResourceEnvironmentModelHandler)

Example 35 with ResourceEnvironment

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);
}
Also used : CloudProfile(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProfile) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) CloudResourceType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudResourceType) VMType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType) CostRepository(de.uka.ipd.sdq.pcm.cost.CostRepository) CostModelHandler(org.iobserve.model.provider.file.CostModelHandler) CloudProvider(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProvider) ResourceEnvironmentModelHandler(org.iobserve.model.provider.file.ResourceEnvironmentModelHandler)

Aggregations

ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)55 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)23 Test (org.junit.Test)15 CostRepository (de.uka.ipd.sdq.pcm.cost.CostRepository)12 Allocation (org.palladiosimulator.pcm.allocation.Allocation)12 LinkingResource (org.palladiosimulator.pcm.resourceenvironment.LinkingResource)12 VMType (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType)11 CloudProfile (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProfile)8 ResourceContainerCloud (org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud)8 System (org.palladiosimulator.pcm.system.System)8 CloudProvider (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProvider)7 CloudResourceType (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudResourceType)7 EObject (org.eclipse.emf.ecore.EObject)6 ProcessingResourceSpecification (org.palladiosimulator.pcm.resourceenvironment.ProcessingResourceSpecification)6 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)6 IOException (java.io.IOException)5 URI (org.eclipse.emf.common.util.URI)5 PCMModelHandler (org.iobserve.model.PCMModelHandler)5 ResourceEnvironmentModelHandler (org.iobserve.model.provider.file.ResourceEnvironmentModelHandler)5 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)5