Search in sources :

Example 26 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class DeployPCMMapperStage method performMapping.

private void performMapping(final EServiceTechnology technology, final String service, final String context, final ISOCountryCode countryCode, final long timestamp) throws InvocationException, DBException {
    final List<AssemblyEntry> assemblyEntry = this.correspondenceModelResource.findObjectsByTypeAndProperty(AssemblyEntry.class, CorrespondencePackage.Literals.ASSEMBLY_ENTRY, "implementationId", context);
    // build the containerAllocationEvent
    final String urlContext = context.replaceAll("\\.", "/");
    final String url = "http://" + service + '/' + urlContext;
    if (assemblyEntry.size() == 1) {
        final AssemblyContext assemblyContext = this.systemModelResource.resolve(assemblyEntry.get(0).getAssembly());
        this.outputPort.send(new PCMDeployedEvent(technology, service, assemblyContext, url, countryCode, timestamp));
    } else if (assemblyEntry.isEmpty()) {
        this.logger.error("Deplyoment failed: No corresponding assembly context {} found on {}.", context, service);
    } else if (assemblyEntry.size() > 1) {
        this.logger.error("Deplyoment failed: Multiple corresponding assembly context {} found on {}.", context, service);
    }
}
Also used : AssemblyEntry(org.iobserve.model.correspondence.AssemblyEntry) PCMDeployedEvent(org.iobserve.analysis.deployment.data.PCMDeployedEvent) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 27 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class DeploymentVisualizationStage method createData.

/**
 * Collects information for creating a service and a service instance element in the
 * visualization. As the order of the changelogs matters, the elements are added to an array in
 * the right order.
 *
 * @param deployment
 *            servlet deployed event
 * @return array that contains changelogs for creating a service and a service instance
 * @throws DBException
 */
private JsonArray createData(final PCMDeployedEvent deployment) throws DBException {
    final String serverName = deployment.getService();
    final String nodeId = this.resourceEnvironmentModelResource.findObjectsByTypeAndProperty(ResourceContainer.class, ResourceenvironmentPackage.Literals.RESOURCE_CONTAINER, "entityName", serverName).get(0).getId();
    final String asmContextName = deployment.getResourceContainer().getEntityName() + "_" + serverName;
    final List<AssemblyContext> contexts = this.allocationModelProvider.findObjectsByTypeAndProperty(AssemblyContext.class, CompositionPackage.Literals.ASSEMBLY_CONTEXT, "entityName", asmContextName);
    final AssemblyContext assemblyContext = contexts.get(0);
    final JsonObject serviceObject = ChangelogHelper.create(this.serviceService.createService(assemblyContext, this.systemId));
    final JsonObject serviceinstanceObject = ChangelogHelper.create(this.serviceinstanceService.createServiceInstance(assemblyContext, this.systemId, nodeId, this.serviceService.getServiceId()));
    return Json.createArrayBuilder().add(serviceObject).add(serviceinstanceObject).build();
}
Also used : JsonObject(javax.json.JsonObject) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 28 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext 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 29 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class AssemblyEntryImpl method setAssembly.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setAssembly(AssemblyContext newAssembly) {
    AssemblyContext oldAssembly = assembly;
    assembly = newAssembly;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, CorrespondencePackage.ASSEMBLY_ENTRY__ASSEMBLY, oldAssembly, assembly));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 30 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemDataFactory method createSystem.

/**
 * Create a {@link System} model based on the given {@link Repository} model.
 *
 * @param repository
 *            the repository model
 * @return returns a {@link System} model
 */
public static System createSystem(final Repository repository) {
    final System system = SystemFactory.eINSTANCE.createSystem();
    system.setEntityName("MyBookstore");
    /**
     * assembly contexts.
     */
    final AssemblyContext queryInputAssemblyContext = SystemDataFactory.createAssemblyContext(repository, SystemDataFactory.QUERY_ASSEMBLY_CONTEXT, RepositoryModelDataFactory.QUERY_COMPONENT);
    final AssemblyContext businessOrderAssemblyContext = SystemDataFactory.createAssemblyContext(repository, SystemDataFactory.BUSINESS_ORDER_ASSEMBLY_CONTEXT, RepositoryModelDataFactory.ORDER_COMPONENT);
    final AssemblyContext privateOrderAssemblyContext = SystemDataFactory.createAssemblyContext(repository, SystemDataFactory.PRIVATE_ORDER_ASSMEBLY_CONTEXT, RepositoryModelDataFactory.ORDER_COMPONENT);
    final AssemblyContext paymentAssemblyContext = SystemDataFactory.createAssemblyContext(repository, SystemDataFactory.PAYMENT_ASSEMBLY_CONTEXT, RepositoryModelDataFactory.PAYMENT_COMPONENT);
    system.getAssemblyContexts__ComposedStructure().add(queryInputAssemblyContext);
    system.getAssemblyContexts__ComposedStructure().add(businessOrderAssemblyContext);
    system.getAssemblyContexts__ComposedStructure().add(paymentAssemblyContext);
    system.getAssemblyContexts__ComposedStructure().add(privateOrderAssemblyContext);
    /**
     * connectors.
     */
    final AssemblyConnector businessQueryInputConnector = SystemDataFactory.createAssemblyConnector(SystemDataFactory.BUSINESS_QUERY_CONNECTOR, businessOrderAssemblyContext, queryInputAssemblyContext);
    final AssemblyConnector privateQueryInputConnector = SystemDataFactory.createAssemblyConnector(SystemDataFactory.PRIVATE_QUERY_CONNECTOR, privateOrderAssemblyContext, queryInputAssemblyContext);
    final AssemblyConnector businessPayConnector = SystemDataFactory.createAssemblyConnector(SystemDataFactory.BUSINESS_PAY_CONNECTOR, paymentAssemblyContext, businessOrderAssemblyContext);
    final AssemblyConnector privatePayConnector = SystemDataFactory.createAssemblyConnector(SystemDataFactory.PRIVATE_PAY_CONNECTOR, paymentAssemblyContext, privateOrderAssemblyContext);
    system.getConnectors__ComposedStructure().add(businessQueryInputConnector);
    system.getConnectors__ComposedStructure().add(privateQueryInputConnector);
    system.getConnectors__ComposedStructure().add(businessPayConnector);
    system.getConnectors__ComposedStructure().add(privatePayConnector);
    return system;
}
Also used : AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) System(org.palladiosimulator.pcm.system.System)

Aggregations

AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)64 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)16 RepositoryComponent (org.palladiosimulator.pcm.repository.RepositoryComponent)11 ArrayList (java.util.ArrayList)9 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)9 AssemblyConnector (org.palladiosimulator.pcm.core.composition.AssemblyConnector)8 System (org.palladiosimulator.pcm.system.System)8 Test (org.junit.Test)7 Connector (org.palladiosimulator.pcm.core.composition.Connector)7 OperationProvidedRole (org.palladiosimulator.pcm.repository.OperationProvidedRole)6 HashSet (java.util.HashSet)5 EObject (org.eclipse.emf.ecore.EObject)5 Allocation (org.palladiosimulator.pcm.allocation.Allocation)5 DataPrivacyLvl (org.palladiosimulator.pcm.compositionprivacy.DataPrivacyLvl)5 OperationRequiredRole (org.palladiosimulator.pcm.repository.OperationRequiredRole)5 ProvidedRole (org.palladiosimulator.pcm.repository.ProvidedRole)5 HashMap (java.util.HashMap)4 AssemblyEntry (org.iobserve.model.correspondence.AssemblyEntry)4 RequiredRole (org.palladiosimulator.pcm.repository.RequiredRole)4 URL (java.net.URL)3