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)));
}
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;
}
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);
}
}
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());
}
}
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)));
}
Aggregations