Search in sources :

Example 1 with ServiceTemplateInstance

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

the class InstanceService method createServiceTemplateInstance.

private ServiceTemplateInstance createServiceTemplateInstance(final CsarId csarId, final String serviceTemplateName, final PlanInstance buildPlanInstance) throws InstantiationException, IllegalAccessException, IllegalArgumentException {
    final Document propertiesAsDoc = createServiceInstanceInitialPropertiesFromServiceTemplate(csarId, serviceTemplateName);
    final ServiceTemplateInstanceProperty property = convertDocumentToProperty(propertiesAsDoc, ServiceTemplateInstanceProperty.class);
    final ServiceTemplateInstance instance = new ServiceTemplateInstance();
    instance.setCsarId(csarId);
    instance.setTemplateId(serviceTemplateName);
    instance.setState(ServiceTemplateInstanceState.INITIAL);
    instance.addProperty(property);
    instance.addPlanInstance(buildPlanInstance);
    instance.setCreationCorrelationId(buildPlanInstance.getCorrelationId());
    this.serviceTemplateInstanceRepository.add(instance);
    if (buildPlanInstance.getServiceTemplateInstance() == null) {
        buildPlanInstance.setServiceTemplateInstance(instance);
    }
    new PlanInstanceRepository().update(buildPlanInstance);
    return instance;
}
Also used : PlanInstanceRepository(org.opentosca.container.core.next.repository.PlanInstanceRepository) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) Document(org.w3c.dom.Document) ServiceTemplateInstanceProperty(org.opentosca.container.core.next.model.ServiceTemplateInstanceProperty)

Example 2 with ServiceTemplateInstance

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

the class InstanceService method setServiceTemplateInstanceState.

public void setServiceTemplateInstanceState(final Long id, final String state) throws NotFoundException, IllegalArgumentException {
    ServiceTemplateInstanceState newState;
    try {
        newState = ServiceTemplateInstanceState.valueOf(state);
    } catch (final Exception e) {
        final String msg = String.format("The given state %s is an illegal service template instance state.", state);
        logger.error(msg, e);
        throw new IllegalArgumentException(msg, e);
    }
    final ServiceTemplateInstance service = getServiceTemplateInstance(id, false);
    service.setState(newState);
    this.serviceTemplateInstanceRepository.update(service);
}
Also used : ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) ServiceTemplateInstanceState(org.opentosca.container.core.next.model.ServiceTemplateInstanceState) NotFoundException(javax.ws.rs.NotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with ServiceTemplateInstance

use of org.opentosca.container.core.next.model.ServiceTemplateInstance 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 4 with ServiceTemplateInstance

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

the class TestUtils method runBuildPlanExecution.

public static ServiceTemplateInstance runBuildPlanExecution(PlanService planService, InstanceService instanceService, Csar csar, TServiceTemplate serviceTemplate, TPlan buildPlan, List<org.opentosca.container.core.extension.TParameter> buildPlanInputParams) {
    String buildPlanCorrelationId = planService.invokePlan(csar, serviceTemplate, -1L, buildPlan.getId(), buildPlanInputParams, PlanType.BUILD);
    if (buildPlan.getPlanLanguage().contains("BPMN")) {
        Collection<ServiceTemplateInstance> coll = instanceService.getServiceTemplateInstances(serviceTemplate.getId());
        ServiceTemplateInstance s = new ServiceTemplateInstance();
        while (coll.size() != 1) {
            coll = instanceService.getServiceTemplateInstances(serviceTemplate.getId());
        }
        for (ServiceTemplateInstance serviceTemplateInstance : coll) {
            s = serviceTemplateInstance;
        }
        ServiceTemplateInstanceState state = instanceService.getServiceTemplateInstanceState(s.getId());
        while ((state != ServiceTemplateInstanceState.CREATED)) {
            state = instanceService.getServiceTemplateInstanceState(s.getId());
        }
        return s;
    }
    PlanInstance buildPlanInstance = planService.getPlanInstanceByCorrelationId(buildPlanCorrelationId);
    while (buildPlanInstance == null) {
        buildPlanInstance = planService.getPlanInstanceByCorrelationId(buildPlanCorrelationId);
    }
    PlanInstanceState buildPlanInstanceState = buildPlanInstance.getState();
    while (!buildPlanInstanceState.equals(PlanInstanceState.FINISHED)) {
        buildPlanInstance = planService.getPlanInstance(buildPlanInstance.getId());
        buildPlanInstanceState = buildPlanInstance.getState();
    }
    return instanceService.getServiceTemplateInstance(buildPlanInstance.getServiceTemplateInstance().getId(), false);
}
Also used : PlanInstance(org.opentosca.container.core.next.model.PlanInstance) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) ServiceTemplateInstanceState(org.opentosca.container.core.next.model.ServiceTemplateInstanceState) PlanInstanceState(org.opentosca.container.core.next.model.PlanInstanceState)

Example 5 with ServiceTemplateInstance

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

the class ServiceTemplateInstanceService method getServiceTemplateInstance.

public ServiceTemplateInstance getServiceTemplateInstance(final Long id, final boolean evaluatePropertyMappings) {
    logger.debug("Requesting service template instance <{}>...", id);
    final Optional<ServiceTemplateInstance> instance = this.serviceTemplateInstanceRepository.findWithNodeAndRelationshipTemplateInstancesById(id);
    if (instance.isPresent()) {
        final ServiceTemplateInstance result = instance.get();
        if (evaluatePropertyMappings) {
            helper.evaluatePropertyMappings(result);
        }
        return result;
    }
    logger.debug("Service Template Instance <" + id + "> not found.");
    throw new NotFoundException("Service Template Instance <" + id + "> not found.");
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance)

Aggregations

ServiceTemplateInstance (org.opentosca.container.core.next.model.ServiceTemplateInstance)45 Csar (org.opentosca.container.core.model.csar.Csar)17 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)15 TPlan (org.eclipse.winery.model.tosca.TPlan)14 NotFoundException (javax.ws.rs.NotFoundException)12 Produces (javax.ws.rs.Produces)11 URI (java.net.URI)10 NodeTemplateInstance (org.opentosca.container.core.next.model.NodeTemplateInstance)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Path (javax.ws.rs.Path)9 CsarId (org.opentosca.container.core.model.csar.CsarId)9 Test (org.junit.Test)8 PlanInstance (org.opentosca.container.core.next.model.PlanInstance)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Document (org.w3c.dom.Document)8 Collectors (java.util.stream.Collectors)7 GET (javax.ws.rs.GET)7 QName (javax.xml.namespace.QName)7 HashMap (java.util.HashMap)6 PlanType (org.opentosca.container.core.next.model.PlanType)6