Search in sources :

Example 1 with PlanType

use of org.opentosca.container.core.next.model.PlanType in project container by OpenTOSCA.

the class PlanService method getPlanInstances.

public List<PlanInstance> getPlanInstances(final Csar csar, final PlanType... planTypes) {
    final ServiceTemplateInstanceRepository repo = new ServiceTemplateInstanceRepository();
    final Collection<ServiceTemplateInstance> serviceInstances = repo.findByCsarId(csar.id());
    return serviceInstances.stream().flatMap(sti -> sti.getPlanInstances().stream()).filter(p -> {
        final PlanType currentType = PlanType.fromString(p.getType().toString());
        return Arrays.stream(planTypes).anyMatch(pt -> pt.equals(currentType));
    }).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) TParameter(org.opentosca.container.core.extension.TParameter) PlanInstanceRepository(org.opentosca.container.core.next.repository.PlanInstanceRepository) LoggerFactory(org.slf4j.LoggerFactory) PlanType(org.opentosca.container.core.next.model.PlanType) DeploymentTestService(org.opentosca.deployment.checks.DeploymentTestService) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Inject(javax.inject.Inject) ServiceTemplateInstanceRepository(org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository) OpenToscaControlService(org.opentosca.container.control.OpenToscaControlService) Service(org.springframework.stereotype.Service) Settings(org.opentosca.container.core.common.Settings) Csar(org.opentosca.container.core.model.csar.Csar) PlanInstance(org.opentosca.container.core.next.model.PlanInstance) Logger(org.slf4j.Logger) PlanInstanceState(org.opentosca.container.core.next.model.PlanInstanceState) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) List(java.util.List) TPlan(org.eclipse.winery.model.tosca.TPlan) Interfaces(org.opentosca.container.core.convention.Interfaces) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) PlanInstanceEvent(org.opentosca.container.core.next.model.PlanInstanceEvent) ServiceTemplateInstanceRepository(org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository) PlanType(org.opentosca.container.core.next.model.PlanType) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance)

Example 2 with PlanType

use of org.opentosca.container.core.next.model.PlanType in project container by OpenTOSCA.

the class CsarController method transformCsar.

@POST
@javax.ws.rs.Path("/transform")
@ApiOperation(value = "Transform this CSAR to a new CSAR")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response transformCsar(@ApiParam(required = true) final CsarTransformRequest request) {
    logger.debug("Invoking transform Csar");
    final CsarId sourceCsarId = new CsarId(request.getSourceCsarName());
    Csar sourceCsar = this.storage.findById(sourceCsarId);
    final CsarId targetCsarId = new CsarId(request.getTargetCsarName());
    Csar targetCsar = this.storage.findById(targetCsarId);
    Collection<AbstractPlan> plansGenerated = this.planGenerationService.generateTransformationPlans(sourceCsar, targetCsar);
    AbstractPlan planGenerated;
    if (plansGenerated.isEmpty()) {
        return Response.serverError().entity("Couldn't generate transformation plan").build();
    } else {
        // we should only have one plan here
        planGenerated = plansGenerated.iterator().next();
    }
    Csar storedCsar = storage.findById(sourceCsarId);
    List<TPlan> plans = this.storage.findById(sourceCsarId).entryServiceTemplate().getPlans();
    TPlan plan = null;
    for (TPlan tPlan : plans) {
        if (tPlan.getId().equals(planGenerated.getId())) {
            plan = tPlan;
            break;
        }
    }
    if (plan == null) {
        return Response.serverError().entity("Couldn't generate transformation plan").build();
    }
    this.controlService.invokePlanDeployment(sourceCsarId, storedCsar.entryServiceTemplate(), plans, plan);
    PlanType[] planTypes = { PlanType.TRANSFORMATION };
    return Response.ok(Utils.getPlanDto(storedCsar, planTypes, plan.getId())).build();
}
Also used : Csar(org.opentosca.container.core.model.csar.Csar) TPlan(org.eclipse.winery.model.tosca.TPlan) PlanType(org.opentosca.container.core.next.model.PlanType) AbstractPlan(org.opentosca.planbuilder.model.plan.AbstractPlan) CsarId(org.opentosca.container.core.model.csar.CsarId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with PlanType

use of org.opentosca.container.core.next.model.PlanType in project container by OpenTOSCA.

the class MBJavaApi method situationAdaption.

@Override
public void situationAdaption(Map<String, Object> eventValues) {
    LOG.debug("Received SituationAware Adapation Event");
    final ServiceTemplateInstance instance = (ServiceTemplateInstance) eventValues.get("SERVICEINSTANCE");
    @SuppressWarnings("unchecked") final Map<String, Collection<Long>> nodeIds2situationIds = (Map<String, Collection<Long>>) eventValues.get("NODE2SITUATIONS");
    Csar csar = this.storage.findById(instance.getCsarId());
    final TTopologyTemplate topology = Lists.newArrayList(csar.entryDefinitions().getServiceTemplates()).get(0).getTopologyTemplate();
    final ServiceTemplateInstanceConfiguration currentConfig = getCurrentServiceTemplateInstanceConfiguration(topology, instance);
    final ServiceTemplateInstanceConfiguration targetConfig = getValidServiceTemplateInstanceConfiguration(topology, nodeIds2situationIds, csar);
    final Collection<String> currentConfigNodeIds = currentConfig.nodeTemplates.stream().map(x -> x.getId()).collect(Collectors.toList());
    final Collection<String> currentConfigRelationIds = currentConfig.relationshipTemplates.stream().map(x -> x.getId()).collect(Collectors.toList());
    final Collection<String> targetConfigNodeIds = targetConfig.nodeTemplates.stream().map(x -> x.getId()).collect(Collectors.toList());
    final Collection<String> targetConfigRelationIds = targetConfig.relationshipTemplates.stream().map(x -> x.getId()).collect(Collectors.toList());
    if (currentConfigNodeIds.equals(targetConfigNodeIds) & currentConfigRelationIds.equals(targetConfigRelationIds)) {
        LOG.debug("Current configuration is equal to target configuration, no adaptation is needed");
        return;
    }
    final Endpoint endpoint = getAdaptationPlanEndpoint(currentConfigNodeIds, currentConfigRelationIds, targetConfigNodeIds, targetConfigRelationIds);
    final String correlationID = String.valueOf(System.currentTimeMillis());
    QName planId = null;
    PlanType planType = null;
    Map<String, String> inputs = null;
    if (endpoint != null) {
        planId = endpoint.getPlanId();
        planType = PlanType.fromString(endpoint.getMetadata().get("PLANTYPE"));
        inputs = new HashMap<>();
        for (final String input : toStringCollection(endpoint.getMetadata().get("INPUTS"), ",")) {
            inputs.put(input, null);
        }
    } else {
        try {
            // FIXME the QName conversion of the instance is probably a bad idea
            final BPELPlan adaptationPlan = (BPELPlan) this.importer.generateAdaptationPlan(csar, QName.valueOf(instance.getTemplateId()), currentConfigNodeIds, currentConfigRelationIds, targetConfigNodeIds, targetConfigRelationIds);
            planType = PlanType.fromString(adaptationPlan.getType().toString());
            inputs = createInput(adaptationPlan);
            final Path tempFile = Files.createTempFile(adaptationPlan.getId(), ".zip");
            this.exporter.exportToPlanFile(tempFile.toUri(), adaptationPlan);
            final Map<String, String> endpointMetadata = toEndpointMetadata(currentConfigNodeIds, currentConfigRelationIds, targetConfigNodeIds, targetConfigRelationIds);
            endpointMetadata.put("PLANTYPE", planType.toString());
            endpointMetadata.put("INPUTS", toCSV(inputs.keySet()));
            planId = new QName(tempFile.getFileName().toString());
            this.bpelDeployPlugin.deployPlanFile(tempFile, instance.getCsarId(), planId, endpointMetadata);
        } catch (final SystemException e) {
            LOG.error("Internal error", e);
            return;
        } catch (final IOException e) {
            LOG.error("Couldn't read files", e);
            return;
        } catch (final JAXBException e) {
            LOG.error("Couldn't parse files", e);
            return;
        }
    }
    final Map<String, String> requestBody = createRequestBody(instance.getCsarId(), instance.getTemplateId(), instance.getId(), inputs, correlationID);
    // FIXME QName natural key replacement leftover!
    invokePlan("adapt", correlationID, instance.getId(), QName.valueOf(instance.getTemplateId()), requestBody, instance.getCsarId(), planId, BPELNS);
}
Also used : ICoreEndpointService(org.opentosca.container.core.service.ICoreEndpointService) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) PlanType(org.opentosca.container.core.next.model.PlanType) Map(java.util.Map) ProducerTemplate(org.apache.camel.ProducerTemplate) URI(java.net.URI) BPELPlan(org.opentosca.planbuilder.model.plan.bpel.BPELPlan) Path(java.nio.file.Path) Settings(org.opentosca.container.core.common.Settings) CsarId(org.opentosca.container.core.model.csar.CsarId) NodeTemplateInstance(org.opentosca.container.core.next.model.NodeTemplateInstance) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) StandardCharsets(java.nio.charset.StandardCharsets) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) UriComponent(org.glassfish.jersey.uri.UriComponent) Endpoint(org.opentosca.container.core.next.model.Endpoint) Importer(org.opentosca.planbuilder.importer.Importer) SituationRepository(org.opentosca.container.core.next.repository.SituationRepository) QName(javax.xml.namespace.QName) TPolicy(org.eclipse.winery.model.tosca.TPolicy) Types(org.opentosca.container.core.convention.Types) DefaultExchange(org.apache.camel.support.DefaultExchange) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) Singleton(javax.inject.Singleton) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) SystemException(org.opentosca.container.core.common.SystemException) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) RelationshipTemplateInstance(org.opentosca.container.core.next.model.RelationshipTemplateInstance) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ModelUtils(org.opentosca.container.core.model.ModelUtils) MBHeader(org.opentosca.bus.management.header.MBHeader) PlanInstanceInput(org.opentosca.container.core.next.model.PlanInstanceInput) CamelContext(org.apache.camel.CamelContext) Csar(org.opentosca.container.core.model.csar.Csar) Logger(org.slf4j.Logger) Files(java.nio.file.Files) BpelPlanEnginePlugin(org.opentosca.container.plan.deployment.plugin.bpel.BpelPlanEnginePlugin) IOException(java.io.IOException) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) IManagementBus(org.opentosca.container.core.engine.management.IManagementBus) NodeTemplateInstanceState(org.opentosca.container.core.next.model.NodeTemplateInstanceState) URLEncoder(java.net.URLEncoder) Component(org.springframework.stereotype.Component) WineryExporter(org.opentosca.planbuilder.export.WineryExporter) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) RelationshipTemplateInstanceState(org.opentosca.container.core.next.model.RelationshipTemplateInstanceState) Path(java.nio.file.Path) Csar(org.opentosca.container.core.model.csar.Csar) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) BPELPlan(org.opentosca.planbuilder.model.plan.bpel.BPELPlan) Endpoint(org.opentosca.container.core.next.model.Endpoint) SystemException(org.opentosca.container.core.common.SystemException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) PlanType(org.opentosca.container.core.next.model.PlanType) Collection(java.util.Collection) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with PlanType

use of org.opentosca.container.core.next.model.PlanType in project container by OpenTOSCA.

the class ServiceTemplateController method transformCsar.

@POST
@Path("/{servicetemplate}/transform")
@ApiOperation(value = "Generates a plan to adapt service template instances via the given the source and target nodes/relations")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response transformCsar(@ApiParam("ID of CSAR") @PathParam("csar") final String csar, @ApiParam("qualified name of the service template") @PathParam("servicetemplate") final String serviceTemplateId, @ApiParam(required = true) final ServiceTransformRequest request) {
    CsarId csarId = new CsarId(csar);
    Csar csarToTransform = this.storage.findById(csarId);
    final AdaptationPlanGenerationResult result = this.planGenerationService.generateAdaptationPlan(csarToTransform, QName.valueOf(serviceTemplateId), request.getSourceNodeTemplates(), request.getSourceRelationshipTemplates(), request.getTargetNodeTemplates(), request.getTargetRelationshipTemplates());
    if (result == null) {
        return Response.serverError().build();
    }
    // FIXME maybe this only makes sense when we have generated plans :/
    this.controlService.declareStored(result.csarId);
    boolean success = this.controlService.invokeToscaProcessing(result.csarId);
    Csar csarFile = this.storage.findById(result.csarId);
    List<TPlan> plans = csarFile.entryServiceTemplate().getPlans();
    TPlan plan = null;
    for (TPlan tPlan : plans) {
        if (tPlan.getId().equals(result.planId)) {
            plan = tPlan;
            break;
        }
    }
    this.controlService.invokePlanDeployment(result.csarId, csarFile.entryServiceTemplate(), plans, plan);
    if (success) {
        PlanType[] planTypes = { PlanType.TRANSFORMATION };
        return Response.ok(Utils.getPlanDto(storage.findById(result.csarId), planTypes, result.planId)).build();
    } else {
        return Response.serverError().build();
    }
}
Also used : Csar(org.opentosca.container.core.model.csar.Csar) TPlan(org.eclipse.winery.model.tosca.TPlan) PlanType(org.opentosca.container.core.next.model.PlanType) AdaptationPlanGenerationResult(org.opentosca.container.control.plan.PlanGenerationService.AdaptationPlanGenerationResult) CsarId(org.opentosca.container.core.model.csar.CsarId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Csar (org.opentosca.container.core.model.csar.Csar)4 PlanType (org.opentosca.container.core.next.model.PlanType)4 TPlan (org.eclipse.winery.model.tosca.TPlan)3 CsarId (org.opentosca.container.core.model.csar.CsarId)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 Settings (org.opentosca.container.core.common.Settings)2 ServiceTemplateInstance (org.opentosca.container.core.next.model.ServiceTemplateInstance)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLEncoder (java.net.URLEncoder)1