Search in sources :

Example 1 with Csar

use of org.opentosca.container.core.model.csar.Csar in project container by OpenTOSCA.

the class OpenToscaControlServiceImpl method generatePlans.

@Override
public boolean generatePlans(CsarId csarId, ServiceTemplateId serviceTemplate) {
    Csar csar = storage.findById(csarId);
    final TServiceTemplate entryServiceTemplate = csar.entryServiceTemplate();
    if (entryServiceTemplate == null) {
        LOGGER.error("No EntryServiceTemplate defined for CSAR [{}]. Aborting plan generation", csarId);
        return false;
    }
    deploymentTracker.storeDeploymentState(csarId, PLAN_DEPLOYMENT_ACTIVE);
    List<TPlan> plans = entryServiceTemplate.getPlans();
    if (plans == null) {
        LOGGER.info("No Plans to process");
        return true;
    }
    String namespace = serviceTemplate.getQName().getNamespaceURI();
    List<TPlan> unDeployed = new ArrayList<>();
    for (final TPlan plan : plans) {
        if (!planEngine.deployPlan(plan, namespace, csarId)) {
            unDeployed.add(plan);
        }
    }
    if (!unDeployed.isEmpty()) {
        LOGGER.error("Plan deployment failed");
        deploymentTracker.storeDeploymentState(csarId, TOSCA_PROCESSED);
        return false;
    }
    LOGGER.info("Successfully deployeed management plans of [{}] in CSAR [{}]", serviceTemplate, csarId);
    deploymentTracker.storeDeploymentState(csarId, PLANS_DEPLOYED);
    // endpointService.printPlanEndpoints();
    return true;
}
Also used : Csar(org.opentosca.container.core.model.csar.Csar) TPlan(org.eclipse.winery.model.tosca.TPlan) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 2 with Csar

use of org.opentosca.container.core.model.csar.Csar 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 3 with Csar

use of org.opentosca.container.core.model.csar.Csar in project container by OpenTOSCA.

the class RelationshipTemplateService method getRelationshipTemplatesOfServiceTemplate.

/**
 * Gets a collection of relationship templates associated to a given service template.
 *
 * @param csarId               The id of the CSAR
 * @param serviceTemplateQName The QName of the service template within the given CSAR
 * @return A collection of relationship templates stored within the given service template.
 */
public List<RelationshipTemplateDTO> getRelationshipTemplatesOfServiceTemplate(final String csarId, final String serviceTemplateQName) {
    final Csar csar = storage.findById(new CsarId(csarId));
    List<TRelationshipTemplate> relationshipTemplates = csar.serviceTemplates().stream().filter(st -> st.getName().equals(serviceTemplateQName)).findFirst().get().getTopologyTemplate().getRelationshipTemplates();
    return relationshipTemplates.stream().map(RelationshipTemplateDTO::fromToscaObject).collect(Collectors.toList());
}
Also used : Csar(org.opentosca.container.core.model.csar.Csar) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) CsarId(org.opentosca.container.core.model.csar.CsarId)

Example 4 with Csar

use of org.opentosca.container.core.model.csar.Csar in project container by OpenTOSCA.

the class CamundaPlanEnginePlugin method planLocationOnDisk.

@Nullable
private Path planLocationOnDisk(CsarId csarId, QName planId, PlanModelReference planRef) {
    if (storage == null) {
        return null;
    }
    Csar csar = storage.findById(csarId);
    IRepository repository = RepositoryFactory.getRepository(csar.getSaveLocation());
    PlanId plan = new PlanId(new PlansId(new ServiceTemplateId(csar.entryServiceTemplate().getTargetNamespace(), csar.entryServiceTemplate().getId(), false)), new XmlId(planId.toString(), false));
    Collection<RepositoryFileReference> fileRefs = repository.getContainedFiles(plan);
    Path planPath = null;
    for (RepositoryFileReference ref : fileRefs) {
        if (ref.getFileName().endsWith(".war")) {
            planPath = repository.ref2AbsolutePath(ref);
            break;
        }
        if (ref.getFileName().endsWith(".zip")) {
            planPath = repository.ref2AbsolutePath(ref);
            break;
        }
    }
    return planPath;
}
Also used : Path(java.nio.file.Path) Csar(org.opentosca.container.core.model.csar.Csar) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) PlanId(org.eclipse.winery.model.ids.elements.PlanId) XmlId(org.eclipse.winery.model.ids.XmlId) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) PlansId(org.eclipse.winery.model.ids.elements.PlansId) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with Csar

use of org.opentosca.container.core.model.csar.Csar in project container by OpenTOSCA.

the class BpelPlanEnginePlugin method planLocationOnDisk.

@Nullable
private Path planLocationOnDisk(CsarId csarId, QName planId, PlanModelReference planRef) {
    if (storage == null) {
        return null;
    }
    Csar csar = storage.findById(csarId);
    IRepository repository = RepositoryFactory.getRepository(csar.getSaveLocation());
    PlanId plan = new PlanId(new PlansId(new ServiceTemplateId(csar.entryServiceTemplate().getTargetNamespace(), csar.entryServiceTemplate().getId(), false)), new XmlId(planId.toString(), false));
    Collection<RepositoryFileReference> fileRefs = repository.getContainedFiles(plan);
    Path planPath = null;
    for (RepositoryFileReference ref : fileRefs) {
        if (ref.getFileName().endsWith(".zip")) {
            planPath = repository.ref2AbsolutePath(ref);
        }
    }
    return planPath;
}
Also used : Path(java.nio.file.Path) Csar(org.opentosca.container.core.model.csar.Csar) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) PlanId(org.eclipse.winery.model.ids.elements.PlanId) XmlId(org.eclipse.winery.model.ids.XmlId) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) PlansId(org.eclipse.winery.model.ids.elements.PlansId) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Csar (org.opentosca.container.core.model.csar.Csar)87 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)54 CsarId (org.opentosca.container.core.model.csar.CsarId)41 Logger (org.slf4j.Logger)31 LoggerFactory (org.slf4j.LoggerFactory)31 QName (javax.xml.namespace.QName)26 TPlan (org.eclipse.winery.model.tosca.TPlan)26 List (java.util.List)24 ServiceTemplateInstance (org.opentosca.container.core.next.model.ServiceTemplateInstance)23 Map (java.util.Map)22 Collectors (java.util.stream.Collectors)22 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)22 Document (org.w3c.dom.Document)22 HashMap (java.util.HashMap)21 NotFoundException (javax.ws.rs.NotFoundException)21 ArrayList (java.util.ArrayList)19 Inject (javax.inject.Inject)18 PlanType (org.opentosca.container.core.next.model.PlanType)18 NotFoundException (org.opentosca.container.core.common.NotFoundException)17 Optional (java.util.Optional)16