Search in sources :

Example 1 with CorrespondenceModel

use of org.iobserve.model.correspondence.CorrespondenceModel in project iobserve-analysis by research-iobserve.

the class CreateCorrespondenceMain method main.

/**
 * @param args
 *            arguments
 */
public static void main(final String[] args) {
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_FrontendService", "jpetstore-frontend-service");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_AccountService", "jpetstore-account-service");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_CatalogService", "jpetstore-catalog-service");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_OdrderService", "jpetstore-order-service");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_AccountDatabase", "jpetstore-account-database");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_CatalogDatabase", "jpetstore-catalog-database");
    CreateCorrespondenceMain.NAME_MAPS.put("Assembly_OrderDatabase", "jpetstore-order-database");
    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 System system = modelHandler.getSystemModel();
        // final Allocation allocation = modelHandler.getAllocationModel();
        final CorrespondenceModel correspondenceModel = CorrespondenceFactory.eINSTANCE.createCorrespondenceModel();
        final Part part = CorrespondenceFactory.eINSTANCE.createPart();
        correspondenceModel.getParts().add(part);
        part.setModelType(system);
        for (final AssemblyContext assembly : system.getAssemblyContexts__ComposedStructure()) {
            final AssemblyEntry entry = CorrespondenceFactory.eINSTANCE.createAssemblyEntry();
            final String value = CreateCorrespondenceMain.NAME_MAPS.get(assembly.getEntityName());
            entry.setImplementationId(value);
            entry.setAssembly(assembly);
            part.getEntries().add(entry);
        }
        final URI outputURI = URI.createFileURI("/home/reiner/correspondence.correspondence");
        CreateCorrespondenceMain.save(correspondenceModel, outputURI);
    } catch (final IOException e) {
        CreateCorrespondenceMain.LOGGER.error("Canot load all models {}", e.getLocalizedMessage());
    }
}
Also used : AssemblyEntry(org.iobserve.model.correspondence.AssemblyEntry) Part(org.iobserve.model.correspondence.Part) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) IOException(java.io.IOException) File(java.io.File) URI(org.eclipse.emf.common.util.URI) System(org.palladiosimulator.pcm.system.System)

Example 2 with CorrespondenceModel

use of org.iobserve.model.correspondence.CorrespondenceModel in project iobserve-analysis by research-iobserve.

the class AnalysisMain method createTeetimeConfiguration.

@Override
protected AnalysisConfiguration createTeetimeConfiguration() throws ConfigurationException {
    /**
     * Configure model handling.
     */
    if (this.parameterConfiguration.isPcmFeature()) {
        try {
            final ModelImporter modelHandler = new ModelImporter(this.parameterConfiguration.getModelInitDirectory());
            /**
             * initialize neo4j graphs.
             */
            final Neo4JModelResource<CorrespondenceModel> correspondenceModelResource = new Neo4JModelResource<>(CorrespondencePackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "correspondence"));
            correspondenceModelResource.storeModelPartition(modelHandler.getCorrespondenceModel());
            final Neo4JModelResource<Repository> repositoryModelResource = new Neo4JModelResource<>(RepositoryPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "repository"));
            repositoryModelResource.storeModelPartition(modelHandler.getRepositoryModel());
            final Neo4JModelResource<ResourceEnvironment> resourceEnvironmentModelResource = new Neo4JModelResource<>(ResourceenvironmentPackage.eINSTANCE, // add
            new File(this.parameterConfiguration.getModelDatabaseDirectory(), "resourceenvironment"));
            resourceEnvironmentModelResource.storeModelPartition(modelHandler.getResourceEnvironmentModel());
            final Neo4JModelResource<System> systemModelResource = new Neo4JModelResource<>(SystemPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "system"));
            systemModelResource.storeModelPartition(modelHandler.getSystemModel());
            final Neo4JModelResource<Allocation> allocationModelResource = new Neo4JModelResource<>(AllocationPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "allocation"));
            allocationModelResource.storeModelPartition(modelHandler.getAllocationModel());
            final Neo4JModelResource<UsageModel> usageModelResource = new Neo4JModelResource<>(UsagemodelPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "usageModel"));
            usageModelResource.storeModelPartition(modelHandler.getUsageModel());
            final Neo4JModelResource<DataProtectionModel> privacyModelResource = new Neo4JModelResource<>(PrivacyPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "privacy"));
            privacyModelResource.storeModelPartition(modelHandler.getPrivacyModel());
            // get systemId
            final System systemModel = systemModelResource.getModelRootNode(System.class, SystemPackage.Literals.SYSTEM);
            this.kiekerConfiguration.setProperty(ConfigurationKeys.SYSTEM_ID, systemModel.getId());
            return new AnalysisConfiguration(this.kiekerConfiguration, repositoryModelResource, resourceEnvironmentModelResource, systemModelResource, allocationModelResource, usageModelResource, correspondenceModelResource);
        } catch (final IOException e) {
            // TODO should be replaced by logger
            // NOPMD
            java.lang.System.err.println("Cannot load all models " + e.getLocalizedMessage());
            // required
            return null;
        } catch (final DBException e) {
            // TODO should be replaced by logger
            // NOPMD
            java.lang.System.err.println("Cannot store all models in DB " + e.getLocalizedMessage());
            // required
            return null;
        }
    } else {
        return new AnalysisConfiguration(this.kiekerConfiguration);
    }
}
Also used : Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) DBException(org.iobserve.model.persistence.DBException) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) DataProtectionModel(org.iobserve.model.privacy.DataProtectionModel) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) IOException(java.io.IOException) System(org.palladiosimulator.pcm.system.System) ModelImporter(org.iobserve.model.ModelImporter) Repository(org.palladiosimulator.pcm.repository.Repository) Allocation(org.palladiosimulator.pcm.allocation.Allocation) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) File(java.io.File)

Example 3 with CorrespondenceModel

use of org.iobserve.model.correspondence.CorrespondenceModel in project iobserve-analysis by research-iobserve.

the class DeploymentExecutor method execute.

@Override
public void execute(final DeployComponentAction action) {
    // Can't be loaded earlier because it references the other models received via TCP
    final CorrespondenceModel correspondenceModel = new FileModelHandler<CorrespondenceModel>(this.resourceSet, CorrespondencePackage.eINSTANCE).load(URI.createFileURI(this.correspondenceModelFile.getAbsolutePath()));
    final KubernetesClient client = new DefaultKubernetesClient();
    final String rcName = this.normalizeComponentName(action.getTargetAllocationContext().getResourceContainer_AllocationContext().getEntityName());
    final Deployment deployment = client.extensions().deployments().inNamespace(this.namespace).withName(rcName).get();
    final AssemblyContext targetAssemblyContext = action.getTargetAllocationContext().getAssemblyContext_AllocationContext();
    final String imageName = this.getImageName(correspondenceModel, targetAssemblyContext);
    if (deployment != null) {
        // Increase number of replicas if pod is already deployed...
        final int replicas = deployment.getSpec().getReplicas();
        deployment.getSpec().setReplicas(replicas + 1);
        client.extensions().deployments().inNamespace(this.namespace).withName(rcName).replace(deployment);
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug("Scaled pod deployment of " + deployment.getMetadata().getName() + " to " + (replicas + 1));
        }
    } else {
        // ... deploy new pod if this is not the case
        final Deployment newDeployment = this.podsToDeploy.get(rcName);
        final String imageLocator = newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
        newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageLocator + "/" + imageName);
        newDeployment.getSpec().getTemplate().getSpec().getContainers().get(0).setName(this.normalizeComponentName(targetAssemblyContext.getEntityName()));
        client.extensions().deployments().inNamespace(this.namespace).create(newDeployment);
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug("Image set to " + imageLocator + "/" + imageName);
            DeploymentExecutor.LOGGER.debug("Created new pod deployment " + newDeployment.getMetadata().getName());
        }
    }
    // Wait until deployed instance is ready
    while (!client.extensions().deployments().inNamespace(this.namespace).withName(rcName).isReady()) {
        if (DeploymentExecutor.LOGGER.isDebugEnabled()) {
            DeploymentExecutor.LOGGER.debug(rcName + " is not ready yet.");
        }
    }
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 4 with CorrespondenceModel

use of org.iobserve.model.correspondence.CorrespondenceModel in project iobserve-analysis by research-iobserve.

the class DeploymentModelUpdater method execute.

/**
 * Execute an deployment event.
 *
 * @param event
 *            one deployment event to be processed
 * @throws NodeLookupException
 *             node lookup failed
 * @throws DBException
 *             on db error
 * @throws InvocationException
 *             on invocation errors
 */
@Override
protected void execute(final PCMDeployedEvent event) throws NodeLookupException, InvocationException, DBException {
    DeploymentLock.lock();
    ExperimentLoggingUtils.logEvent(event.getTimestamp(), EventTypes.DEPLOYMENT, ObservationPoint.MODEL_UPDATE_ENTRY);
    this.logger.debug("Send event from {}", this.getInputPort().getPipe().getSourcePort().getOwningStage().getId());
    this.logger.debug("Deployment model update: assemblyContext={} resourceContainer={} service={}", event.getAssemblyContext(), event.getResourceContainer(), event.getService());
    final String allocationContextName = NameFactory.createAllocationContextName(event.getAssemblyContext(), event.getResourceContainer());
    final List<AllocationContext> allocationContext = this.allocationModelResource.findObjectsByTypeAndProperty(AllocationContext.class, AllocationPackage.Literals.ALLOCATION_CONTEXT, "entityName", allocationContextName);
    if (allocationContext.isEmpty()) {
        this.logger.debug("Create allocation context (deploy) {}", event);
        final Allocation allocationModel = this.allocationModelResource.getModelRootNode(Allocation.class, AllocationPackage.Literals.ALLOCATION);
        final AllocationContext newAllocationContext = AllocationFactory.eINSTANCE.createAllocationContext();
        newAllocationContext.setEntityName(allocationContextName);
        newAllocationContext.setAssemblyContext_AllocationContext(event.getAssemblyContext());
        newAllocationContext.setResourceContainer_AllocationContext(event.getResourceContainer());
        allocationModel.getAllocationContexts_Allocation().add(newAllocationContext);
        this.allocationModelResource.updatePartition(allocationModel);
        final AllocationContext storedAllocationContext = this.allocationModelResource.resolve(newAllocationContext);
        /**
         * create correspondence model entry.
         */
        final CorrespondenceModel correspondenceModel = this.correspondenceModelResource.getModelRootNode(CorrespondenceModel.class, CorrespondencePackage.Literals.CORRESPONDENCE_MODEL);
        final Part part = this.findOrCreate(correspondenceModel, allocationModel);
        final AllocationEntry entry = CorrespondenceFactory.eINSTANCE.createAllocationEntry();
        entry.setAllocation(storedAllocationContext);
        entry.setTechnology(event.getTechnology());
        entry.setImplementationId(event.getUrl());
        part.getEntries().add(entry);
        this.correspondenceModelResource.updatePartition(correspondenceModel);
        this.logger.debug("PUSHED CORRESPONDENCE {} {} {}", newAllocationContext.getEntityName(), event.getTechnology().getLiteral(), event.getUrl());
    } else {
        this.logger.error("Deployment failed: Allocation Context {} already exists in allocation model.", allocationContextName);
    }
    // signal deployment update
    ExperimentLoggingUtils.logEvent(event.getTimestamp(), EventTypes.DEPLOYMENT, ObservationPoint.MODEL_UPDATE_EXIT);
    DeploymentLock.unlock();
    this.deployedNotifyOutputPort.send(event);
}
Also used : AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) AllocationEntry(org.iobserve.model.correspondence.AllocationEntry) Allocation(org.palladiosimulator.pcm.allocation.Allocation) Part(org.iobserve.model.correspondence.Part) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel)

Example 5 with CorrespondenceModel

use of org.iobserve.model.correspondence.CorrespondenceModel in project iobserve-analysis by research-iobserve.

the class PrivacyViolationDetectionServiceMain method createTeetimeConfiguration.

@Override
protected PipelineConfiguration createTeetimeConfiguration() throws ConfigurationException {
    /**
     * load models.
     */
    try {
        final ModelImporter modelHandler = new ModelImporter(this.parameterConfiguration.getModelInitDirectory());
        /**
         * initialize database.
         */
        final IModelResource<CorrespondenceModel> correspondenceModelResource = this.loadResourceAndInitDB(CorrespondencePackage.eINSTANCE, modelHandler.getCorrespondenceModel());
        final IModelResource<Repository> repositoryModelResource = this.loadResourceAndInitDB(RepositoryPackage.eINSTANCE, modelHandler.getRepositoryModel());
        final IModelResource<ResourceEnvironment> resourceEnvironmentModelResource = this.loadResourceAndInitDB(ResourceenvironmentPackage.eINSTANCE, modelHandler.getResourceEnvironmentModel());
        final IModelResource<System> systemModelResource = this.loadResourceAndInitDB(SystemPackage.eINSTANCE, modelHandler.getSystemModel());
        final IModelResource<Allocation> allocationModelResource = this.loadResourceAndInitDB(AllocationPackage.eINSTANCE, modelHandler.getAllocationModel());
        final IModelResource<DataProtectionModel> privacyModelResource = this.loadResourceAndInitDB(PrivacyPackage.eINSTANCE, modelHandler.getPrivacyModel());
        return new PipelineConfiguration(this.kiekerConfiguration, correspondenceModelResource, repositoryModelResource, resourceEnvironmentModelResource, systemModelResource, allocationModelResource, privacyModelResource, this.parameterConfiguration.getWarningFile(), this.parameterConfiguration.getAlarmsFile(), this.parameterConfiguration.getModelDumpDirectory());
    } catch (final DBException | IOException e) {
        throw new ConfigurationException(e);
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) DataProtectionModel(org.iobserve.model.privacy.DataProtectionModel) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) IOException(java.io.IOException) System(org.palladiosimulator.pcm.system.System) ModelImporter(org.iobserve.model.ModelImporter) Repository(org.palladiosimulator.pcm.repository.Repository) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ConfigurationException(kieker.common.exception.ConfigurationException)

Aggregations

CorrespondenceModel (org.iobserve.model.correspondence.CorrespondenceModel)5 IOException (java.io.IOException)3 Allocation (org.palladiosimulator.pcm.allocation.Allocation)3 System (org.palladiosimulator.pcm.system.System)3 File (java.io.File)2 ModelImporter (org.iobserve.model.ModelImporter)2 Part (org.iobserve.model.correspondence.Part)2 DBException (org.iobserve.model.persistence.DBException)2 DataProtectionModel (org.iobserve.model.privacy.DataProtectionModel)2 AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)2 Repository (org.palladiosimulator.pcm.repository.Repository)2 ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 ConfigurationException (kieker.common.exception.ConfigurationException)1 URI (org.eclipse.emf.common.util.URI)1 AllocationEntry (org.iobserve.model.correspondence.AllocationEntry)1 AssemblyEntry (org.iobserve.model.correspondence.AssemblyEntry)1 Neo4JModelResource (org.iobserve.model.persistence.neo4j.Neo4JModelResource)1