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 ModelImporter 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 CreatePrivacyMain method main.
/**
* @param args
* arguments
*/
public static void main(final String[] args) {
CreatePrivacyMain.createIsoCodes();
CreatePrivacyMain.createPrivacyAnnotations();
final String pcmDirectory = "/home/reiner/Projects/iObserve/experiments/distributed-jpetstore-experiment/pcm/JPetStore";
try {
final ModelImporter modelHandler = new ModelImporter(new File(pcmDirectory));
final Repository repository = modelHandler.getRepositoryModel();
final ResourceEnvironment environment = modelHandler.getResourceEnvironmentModel();
final DataProtectionModel privacyModel = PrivacyFactory.eINSTANCE.createDataProtectionModel();
CreatePrivacyMain.addGeoLocations(privacyModel, environment);
CreatePrivacyMain.addPrivacyAnnotations(privacyModel, repository);
final URI outputURI = URI.createFileURI("/home/reiner/privacyTestModel.privacy");
CreatePrivacyMain.save(privacyModel, outputURI);
} catch (final IOException e) {
CreatePrivacyMain.LOGGER.error("Canot load all models {}", e.getLocalizedMessage());
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ResourceEnvironmentModelProviderTest method createThenUpdateThenReadUpdated.
/**
* Test whether update works correctly.
*
* @throws NodeLookupException
* @throws DBException
*/
@Override
@Test
public void createThenUpdateThenReadUpdated() throws NodeLookupException, DBException {
final Neo4JModelResource<ResourceEnvironment> resource = ModelProviderTestUtils.prepareResource("createThenUpdateThenReadUpdated", this.prefix, this.ePackage);
resource.storeModelPartition(this.testModel);
final ResourceContainer orderServer = ResourceEnvironmentDataFactory.findContainer(this.resourceEnvironment, ResourceEnvironmentDataFactory.BUSINESS_ORDER_CONTAINER);
final LinkingResource writtenLan1 = ResourceEnvironmentDataFactory.findLinkingResource(this.resourceEnvironment, ResourceEnvironmentDataFactory.LAN_1);
// Update the model by replacing the orderServer by two separated servers
this.testModel.getResourceContainer_ResourceEnvironment().remove(orderServer);
writtenLan1.getConnectedResourceContainers_LinkingResource().remove(orderServer);
final ResourceContainer businessOrderServer = ResourceenvironmentFactory.eINSTANCE.createResourceContainer();
final ProcessingResourceSpecification businessOrderServerSpecification = ResourceenvironmentFactory.eINSTANCE.createProcessingResourceSpecification();
final ProcessingResourceType businessOrderServerType = ResourcetypeFactory.eINSTANCE.createProcessingResourceType();
businessOrderServer.setEntityName("businessOrderServer");
businessOrderServer.setResourceEnvironment_ResourceContainer(this.testModel);
businessOrderServer.getActiveResourceSpecifications_ResourceContainer().add(businessOrderServerSpecification);
businessOrderServerSpecification.setActiveResourceType_ActiveResourceSpecification(businessOrderServerType);
businessOrderServerType.setEntityName("Cisco Business Server PRO");
final ResourceContainer privateOrderServer = ResourceenvironmentFactory.eINSTANCE.createResourceContainer();
final ProcessingResourceSpecification privateOrderServerSpecification = ResourceenvironmentFactory.eINSTANCE.createProcessingResourceSpecification();
final ProcessingResourceType privateOrderServerType = ResourcetypeFactory.eINSTANCE.createProcessingResourceType();
privateOrderServer.setEntityName("privateOrderServer");
privateOrderServer.setResourceEnvironment_ResourceContainer(this.testModel);
privateOrderServer.getActiveResourceSpecifications_ResourceContainer().add(privateOrderServerSpecification);
privateOrderServerSpecification.setActiveResourceType_ActiveResourceSpecification(privateOrderServerType);
privateOrderServerType.setEntityName("Lenovo High Load Server PRO");
this.testModel.getResourceContainer_ResourceEnvironment().add(businessOrderServer);
this.testModel.getResourceContainer_ResourceEnvironment().add(privateOrderServer);
writtenLan1.getConnectedResourceContainers_LinkingResource().add(businessOrderServer);
writtenLan1.getConnectedResourceContainers_LinkingResource().add(privateOrderServer);
resource.updatePartition(this.testModel);
final ResourceEnvironment readModel = resource.getModelRootNode(ResourceEnvironment.class, this.eClass);
Assert.assertTrue(this.equalityHelper.comparePartition(this.testModel, readModel, readModel.eClass()));
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class InitializeDeploymentVisualization method initialize.
/**
* Populates the database of the deployment visualization initially and respects the changelog
* constraints of iobserve-ui-deployment. It takes information from the system model, the
* allocation model and the resource environment model and creates corresponding visualization
* components, e.g. nodes and services.
*
* @throws IOException
* when post request fails
*/
public void initialize() throws IOException {
// set up the system model and take parts from it
final org.palladiosimulator.pcm.system.System systemModel = this.systemModelGraphProvider.readOnlyRootComponent(org.palladiosimulator.pcm.system.System.class);
final List<AssemblyContext> assemblyContexts = systemModel.getAssemblyContexts__ComposedStructure();
// set up the allocation model and take parts from it
final List<String> allocationIds = this.allocationModelGraphProvider.readComponentByType(Allocation.class);
// an allocation model contains exactly one allocation, therefore .get(0)
final String allocationId = allocationIds.get(0);
final Allocation allocation = this.allocationModelGraphProvider.readOnlyComponentById(Allocation.class, allocationId);
final List<AllocationContext> allocationContexts = allocation.getAllocationContexts_Allocation();
// set up the resource environment model and take parts from it
final ResourceEnvironment resourceEnvironmentModel = this.resourceEnvironmentModelGraphProvider.readOnlyRootComponent(ResourceEnvironment.class);
final List<LinkingResource> linkingResources = resourceEnvironmentModel.getLinkingResources__ResourceEnvironment();
final List<ResourceContainer> resourceContainers = resourceEnvironmentModel.getResourceContainer_ResourceEnvironment();
// sending created components to visualization (in predefined order stated in changelog
// constraints)
/**
* system
*/
SendHttpRequest.post(this.systemService.createSystem(systemModel), this.systemUrl, this.changelogUrl);
/**
* node group and node
*/
for (int i = 0; i < resourceContainers.size(); i++) {
final ResourceContainer resourceContainer = resourceContainers.get(i);
SendHttpRequest.post(Changelog.create(this.nodegroupService.createNodegroup(this.systemService.getSystemId())), this.systemUrl, this.changelogUrl);
SendHttpRequest.post(Changelog.create(this.nodeService.createNode(resourceContainer, this.systemService.getSystemId(), this.nodegroupService.getNodegroupId())), this.systemUrl, this.changelogUrl);
}
/**
* service and service instance
*/
for (int i = 0; i < assemblyContexts.size(); i++) {
final AssemblyContext assemblyContext = assemblyContexts.get(i);
SendHttpRequest.post(Changelog.create(this.serviceService.createService(assemblyContext, this.systemService.getSystemId())), this.systemUrl, this.changelogUrl);
}
for (int i = 0; i < allocationContexts.size(); i++) {
final AllocationContext allocationContext = allocationContexts.get(i);
final String resourceContainerId = allocationContext.getResourceContainer_AllocationContext().getId();
final AssemblyContext assemblyContext = allocationContext.getAssemblyContext_AllocationContext();
final String assemblyContextId = allocationContext.getAssemblyContext_AllocationContext().getId();
SendHttpRequest.post(Changelog.create(this.serviceinstanceService.createServiceInstance(assemblyContext, this.systemService.getSystemId(), resourceContainerId, assemblyContextId)), this.systemUrl, this.changelogUrl);
}
/**
* communication and communication instance
*/
final List<Connector> connectors = systemModel.getConnectors__ComposedStructure();
for (int i = 0; i < connectors.size(); i++) {
final Connector connector = connectors.get(i);
// we are only interested in AssemblyConnectors
if (connector instanceof AssemblyConnector) {
final String technology = this.getTechnology((AssemblyConnector) connector, linkingResources);
SendHttpRequest.post(Changelog.create(this.communicationService.createCommunication((AssemblyConnector) connector, this.systemService.getSystemId(), technology)), this.systemUrl, this.changelogUrl);
SendHttpRequest.post(Changelog.create(this.communicationinstanceService.createCommunicationInstance((AssemblyConnector) connector, this.systemService.getSystemId(), this.communicationService.getCommunicationId())), this.systemUrl, this.changelogUrl);
} else {
InitializeDeploymentVisualization.LOGGER.debug("no AssemblyConnector: connector.getEntityName()");
}
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ResourceContainerActionFactory method createReplicateAction.
/**
* Create replicate action.
*
* @param runtimeServer
* source server
* @param reDeploymentServer
* target server
* @return the action
*/
public static ReplicateAction createReplicateAction(final DeploymentNode runtimeServer, final DeploymentNode reDeploymentServer) {
final SystemadaptationFactory factory = SystemadaptationFactory.eINSTANCE;
final ReplicateAction action = factory.createReplicateAction();
ResourceContainerActionFactory.setSourceResourceContainer(action, runtimeServer.getResourceContainerID());
final Allocation runtimeAllocModel = ActionFactory.getRuntimeModels().getAllocationModel();
for (final ComponentNode component : runtimeServer.getContainingComponents()) {
final AllocationContext oldAllocationContext = ActionFactory.getAllocationContext(component.getAllocationContextID(), runtimeAllocModel);
action.getSourceAllocationContext().add(oldAllocationContext);
}
final Allocation reDeplAllocModel = ActionFactory.getRedeploymentModels().getAllocationModel();
for (final ComponentNode component : reDeploymentServer.getContainingComponents()) {
final AllocationContext newAllocationContext = ActionFactory.getAllocationContext(component.getAllocationContextID(), reDeplAllocModel);
action.getSourceAllocationContext().add(newAllocationContext);
}
final ResourceEnvironment resEnvModel = ActionFactory.getRedeploymentModels().getResourceEnvironmentModel();
final ResourceContainer newResourceContainer = ActionFactory.getResourceContainer(reDeploymentServer.getResourceContainerID(), resEnvModel);
action.setNewResourceContainer(newResourceContainer);
return action;
}
Aggregations