Search in sources :

Example 46 with ResourceEnvironment

use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.

the class AllocationResourceContainerTest method stubMocksResourceContainer.

/**
 * Define the test situation in which a {@link ContainerAllocationEvent} is defined as input and
 * the specified {@link ResourceContainer} does exist in the {@link ResourceEnvironment}.
 *
 * @throws DBException
 */
@SuppressWarnings("unchecked")
@Before
public void stubMocksResourceContainer() throws DBException {
    /**
     * mock for ResourceEnvironmentModelBuilder
     */
    // use PowerMockito for calling static methods of this final class
    PowerMockito.mockStatic(ResourceEnvironmentModelFactory.class);
    /**
     * mock for new graph provider
     */
    AllocationResourceContainerTest.mockedResourceEnvironmentModelGraphProvider = Mockito.mock(Neo4JModelResource.class);
    this.allocationStage = new AllocationStage(AllocationResourceContainerTest.mockedResourceEnvironmentModelGraphProvider);
    Mockito.when(AllocationResourceContainerTest.mockedResourceEnvironmentModelGraphProvider.getModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT)).thenReturn(AllocationResourceContainerTest.resourceEnvironment);
    Mockito.when(ResourceEnvironmentModelFactory.getResourceContainerByName(AllocationResourceContainerTest.mockedResourceEnvironmentModelGraphProvider.getModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT), ImplementationLevelDataFactory.SERVICE)).thenReturn(Optional.of(AllocationResourceContainerTest.resourceEnvironment.getResourceContainer_ResourceEnvironment().get(0)));
}
Also used : Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) AllocationStage(org.iobserve.analysis.deployment.AllocationStage) Before(org.junit.Before)

Example 47 with ResourceEnvironment

use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.

the class ResourceContainerActionFactory method createDeallocateAction.

/**
 * Create a deallocate action.
 *
 * @param runtimeServer
 *            the node going to be deallocated
 * @return the action
 */
public static DeallocateAction createDeallocateAction(final DeploymentNode runtimeServer) {
    final DeallocateAction action = SystemadaptationFactory.eINSTANCE.createDeallocateAction();
    final ResourceEnvironment runtimeResourceEnvironment = ActionFactory.getRuntimeModels().getResourceEnvironmentModel();
    ResourceContainerActionFactory.initializeResourceContainerAction(action, runtimeServer, runtimeResourceEnvironment);
    return action;
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) DeallocateAction(org.iobserve.planning.systemadaptation.DeallocateAction)

Example 48 with ResourceEnvironment

use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.

the class DeallocationStage method execute.

@Override
protected void execute(final IDeallocationEvent event) throws Exception {
    final String service;
    if (event instanceof ContainerAllocationEvent) {
        service = ((ContainerAllocationEvent) event).getService();
    } else {
        throw new UnknownObjectException(event.getClass() + " is not supported by the allocation filter.");
    }
    final Optional<ResourceContainer> resourceContainer = ResourceEnvironmentModelFactory.getResourceContainerByName(this.resourceEnvironmentResource.getModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT), service);
    if (resourceContainer.isPresent()) {
        /**
         * new provider: update the resource environment graph.
         */
        final ResourceEnvironment resourceEnvironmentModelGraph = this.resourceEnvironmentResource.getModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT);
        resourceEnvironmentModelGraph.getResourceContainer_ResourceEnvironment().remove(resourceContainer.get());
        this.resourceEnvironmentResource.updatePartition(resourceEnvironmentModelGraph);
        /**
         * signal allocation update.
         */
        this.deallocationNotifyOutputPort.send(resourceContainer.get());
        this.deallocationOutputPort.send(event);
    } else {
        /**
         * error deallocation already happened.
         */
        this.logger.error("ResourceContainer {} is missing.", service);
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ContainerAllocationEvent(org.iobserve.common.record.ContainerAllocationEvent) UnknownObjectException(java.rmi.activation.UnknownObjectException) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 49 with ResourceEnvironment

use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.

the class AllocationStage method execute.

/**
 * This method is triggered for every allocation event.
 *
 * @param event
 *            one allocation event to be processed
 * @throws MalformedURLException
 *             malformed url exception
 * @throws UnknownObjectException
 *             in case the allocation event is of an unknown type
 * @throws NodeLookupException
 *             node lookup exception
 * @throws DBException
 *             on database errors
 */
@Override
protected void execute(final IAllocationEvent event) throws MalformedURLException, UnknownObjectException, NodeLookupException, DBException {
    final String service;
    if (event instanceof ContainerAllocationEvent) {
        service = ((ContainerAllocationEvent) event).getService();
        this.logger.debug("Allocate {}", service);
    } else {
        this.logger.error("Unknown allocation event type {}", event.getClass());
        throw new UnknownObjectException(String.format("%s is not supported by the allocation filter.", event.getClass().getCanonicalName()));
    }
    final ResourceEnvironment resourceEnvironment = this.resourceEnvironmentResource.getModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT);
    final Optional<ResourceContainer> resourceContainer = ResourceEnvironmentModelFactory.getResourceContainerByName(resourceEnvironment, service);
    if (!resourceContainer.isPresent()) {
        this.logger.debug("ResourceContainer {} has to be created.", service);
        final ResourceContainer newResourceContainer = ResourceEnvironmentModelFactory.createResourceContainer(resourceEnvironment, service);
        resourceEnvironment.getResourceContainer_ResourceEnvironment().add(newResourceContainer);
        this.resourceEnvironmentResource.updatePartition(resourceEnvironment);
        /**
         * signal allocation update.
         */
        this.allocationNotifyOutputPort.send(newResourceContainer);
        this.allocationOutputPort.send(event);
    } else {
        /**
         * error allocation already happened.
         */
        this.logger.debug("ResourceContainer {} was available.", service);
        final List<ProcessingResourceSpecification> procResSpec = resourceContainer.get().getActiveResourceSpecifications_ResourceContainer();
        for (int i = 0; i < procResSpec.size(); i++) {
            final String nodeGroupName = procResSpec.get(i).getActiveResourceType_ActiveResourceSpecification().getEntityName();
            this.logger.debug(nodeGroupName);
        }
        /**
         * Notify with existing container.
         */
        this.allocationNotifyOutputPort.send(resourceContainer.get());
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ContainerAllocationEvent(org.iobserve.common.record.ContainerAllocationEvent) ProcessingResourceSpecification(org.palladiosimulator.pcm.resourceenvironment.ProcessingResourceSpecification) UnknownObjectException(java.rmi.activation.UnknownObjectException) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 50 with ResourceEnvironment

use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.

the class ResourceEnvironmentModelProviderTest method createThenReadReferencing.

/**
 * Check is references are resolved correctly.
 *
 * @throws DBException
 */
@Override
@Test
public void createThenReadReferencing() throws DBException {
    final Neo4JModelResource<ResourceEnvironment> resource = ModelProviderTestUtils.prepareResource("createThenReadReferencing", this.prefix, this.ePackage);
    resource.storeModelPartition(this.testModel);
    final LinkingResource linkingResource = ResourceEnvironmentDataFactory.findLinkingResource(this.resourceEnvironment, ResourceEnvironmentDataFactory.LAN_1);
    final CommunicationLinkResourceSpecification resourceSpecification = linkingResource.getCommunicationLinkResourceSpecifications_LinkingResource();
    final CommunicationLinkResourceType lanType = resourceSpecification.getCommunicationLinkResourceType_CommunicationLinkResourceSpecification();
    final List<EObject> readReferencingComponents = resource.collectReferencingObjectsByTypeAndProperty(CommunicationLinkResourceType.class, ResourcetypePackage.Literals.COMMUNICATION_LINK_RESOURCE_TYPE, ModelGraphFactory.getIdentification(lanType));
    // Only the lan1 CommunicationLinkResourceSpecification is referencing the lan1
    // CommunicationLinkResourceType
    Assert.assertTrue(readReferencingComponents.size() == 1);
    Assert.assertTrue(this.equalityHelper.compareObject(resourceSpecification, readReferencingComponents.get(0)));
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) CommunicationLinkResourceSpecification(org.palladiosimulator.pcm.resourceenvironment.CommunicationLinkResourceSpecification) CommunicationLinkResourceType(org.palladiosimulator.pcm.resourcetype.CommunicationLinkResourceType) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

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