Search in sources :

Example 1 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class InstanceModelRefinement method refine.

public TTopologyTemplate refine(ServiceTemplateId serviceTemplateId) {
    IRepository repository = RepositoryFactory.getRepository();
    TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
    TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
    List<DiscoveryPluginDescriptor> discoveryPluginDescriptors = extractDiscoveryPluginsFromServiceTemplate(serviceTemplate, new ObjectMapper());
    if (topologyTemplate == null) {
        logger.error("Cannot refine empty instance model!");
        return null;
    }
    boolean pluginsAreAvailable = true;
    do {
        ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topologyTemplate);
        List<InstanceModelRefinementPlugin> executablePlugins = this.plugins.stream().filter(plugin -> plugin.isApplicable(topologyTemplate, topologyGraph)).collect(Collectors.toList());
        InstanceModelRefinementPlugin selectedPlugin = pluginChooser.selectPlugin(topologyTemplate, executablePlugins);
        if (selectedPlugin != null) {
            DiscoveryPluginDescriptor discoveryPlugin = discoveryPluginDescriptors.stream().filter(discoveryPluginDescriptor -> Objects.equals(discoveryPluginDescriptor.getId(), selectedPlugin.getId())).findAny().orElseGet(() -> {
                DiscoveryPluginDescriptor discoveryPluginDescriptor = new DiscoveryPluginDescriptor();
                discoveryPluginDescriptor.setId(selectedPlugin.getId());
                discoveryPluginDescriptor.setDiscoveredIds(Collections.emptyList());
                discoveryPluginDescriptors.add(discoveryPluginDescriptor);
                return discoveryPluginDescriptor;
            });
            Set<String> pluginDiscoveredNodeIds = selectedPlugin.apply(topologyTemplate);
            List<String> discoveredIds = new ArrayList<>();
            discoveredIds.addAll(pluginDiscoveredNodeIds);
            discoveredIds.addAll(discoveryPlugin.getDiscoveredIds());
            discoveryPlugin.setDiscoveredIds(discoveredIds);
            updateDiscoveryPluginsInServiceTemplate(serviceTemplate, new ObjectMapper(), discoveryPluginDescriptors);
            try {
                repository.setElement(serviceTemplateId, serviceTemplate);
            } catch (IOException e) {
                logger.error("Error persisting Service Template {}", serviceTemplateId.toReadableString());
            }
        } else {
            pluginsAreAvailable = false;
        }
    } while (pluginsAreAvailable);
    return topologyTemplate;
}
Also used : Arrays(java.util.Arrays) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DiscoveryPluginDescriptor(org.eclipse.winery.model.tosca.DiscoveryPluginDescriptor) LoggerFactory(org.slf4j.LoggerFactory) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) PetClinicRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.PetClinicRefinementPlugin) DockerImageRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.dockerimage.DockerImageRefinementPlugin) TomcatRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.TomcatRefinementPlugin) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) MySqlDbmsRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbmsRefinementPlugin) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Collectors(java.util.stream.Collectors) TTag(org.eclipse.winery.model.tosca.TTag) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) MySqlDbRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.MySqlDbRefinementPlugin) Objects(java.util.Objects) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) Ec2AmiRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.Ec2AmiRefinementPlugin) SpringWebAppRefinementPlugin(org.eclipse.winery.model.adaptation.instance.plugins.SpringWebAppRefinementPlugin) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) Collections(java.util.Collections) ToscaTransformer(org.eclipse.winery.topologygraph.transformation.ToscaTransformer) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) DiscoveryPluginDescriptor(org.eclipse.winery.model.tosca.DiscoveryPluginDescriptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 2 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class AbstractSubstitution method getSubstitutionServiceTemplateId.

/**
 * Creates a new version of the given Service Template for the substitution.
 * If no new version can be created, the given Service Template will be returned.
 *
 * @param serviceTemplateId the Service Template containing abstract types to be substituted
 * @return the new Id of the Service Template
 */
protected ServiceTemplateId getSubstitutionServiceTemplateId(ServiceTemplateId serviceTemplateId) {
    try {
        ServiceTemplateId substitutedServiceTemplateId = new ServiceTemplateId(serviceTemplateId.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(serviceTemplateId, versionAppendix), false);
        repository.duplicate(serviceTemplateId, substitutedServiceTemplateId);
        LOGGER.debug("Created new Service Template version {}", substitutedServiceTemplateId);
        return substitutedServiceTemplateId;
    } catch (IOException e) {
        LOGGER.debug("Could not create new Service Template version during substitution", e);
        LOGGER.debug("Reusing existing element");
    }
    return serviceTemplateId;
}
Also used : IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId)

Example 3 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class AccountabilityResource method getFileHistory.

@GET
@Path("fileHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<FileProvenanceElement> getFileHistory(@QueryParam("fileId") String fileId) {
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
    String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
    Objects.requireNonNull(fileId);
    String fileIdDecoded = EncodingUtil.URLdecode(fileId);
    try {
        return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly, fileIdDecoded).exceptionally(error -> null).get();
    } catch (InterruptedException | ExecutionException | AccountabilityException e) {
        LOGGER.error("Cannot history of file {}. Reason: {}", fileId, e.getMessage());
        throw createException(e);
    }
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ArrayList(java.util.ArrayList) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Charset(java.nio.charset.Charset) Consumes(javax.ws.rs.Consumes) VersionSupport(org.eclipse.winery.model.version.VersionSupport) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AuthorizationNode(org.eclipse.winery.accountability.model.authorization.AuthorizationNode) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final TDefinitions definitions = createWrapperDefinitions(id, repository);
    HasIdInIdOrNameField element;
    if (id instanceof RelationshipTypeImplementationId) {
        element = new TRelationshipTypeImplementation();
    } else if (id instanceof NodeTypeImplementationId) {
        element = new TNodeTypeImplementation();
    } else if (id instanceof RequirementTypeId) {
        element = new TRequirementType();
    } else if (id instanceof NodeTypeId) {
        element = new TNodeType();
    } else if (id instanceof RelationshipTypeId) {
        element = new TRelationshipType();
    } else if (id instanceof CapabilityTypeId) {
        element = new TCapabilityType();
    } else if (id instanceof DataTypeId) {
        element = new TDataType();
    } else if (id instanceof ArtifactTypeId) {
        element = new TArtifactType();
    } else if (id instanceof PolicyTypeId) {
        element = new TPolicyType();
    } else if (id instanceof PolicyTemplateId) {
        element = new TPolicyTemplate();
    } else if (id instanceof ServiceTemplateId) {
        element = new TServiceTemplate();
    } else if (id instanceof ArtifactTemplateId) {
        element = new TArtifactTemplate();
    } else if (id instanceof ComplianceRuleId) {
        element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
    } else if (id instanceof PatternRefinementModelId) {
        element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TopologyFragmentRefinementModelId) {
        element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TestRefinementModelId) {
        element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
    } else if (id instanceof InterfaceTypeId) {
        element = new TInterfaceType();
    } else if (id instanceof XSDImportId) {
        // TImport has no id; thus directly generating it without setting an id
        TImport tImport = new TImport();
        definitions.setElement(tImport);
        return definitions;
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
    copyIdToFields(element, id);
    definitions.setElement((TExtensibleElements) element);
    return definitions;
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 5 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class ConsistencyChecker method checkAllDefinitions.

private void checkAllDefinitions(IRepository repository) {
    final Path tempCsar;
    try {
        tempCsar = Files.createTempFile("Export", ".csar");
    } catch (IOException e) {
        LOGGER.debug("Could not create temp CSAR file", e);
        errorCollector.error("Could not create temp CSAR file");
        return;
    }
    float elementsChecked = 0;
    int size = allDefinitionsChildIds.size();
    Map<QName, TDefinitions> allQNameToDefinitionMapping = repository.getAllQNameToDefinitionsMapping();
    for (DefinitionsChildId id : allDefinitionsChildIds) {
        float progress = ++elementsChecked / size;
        if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) {
            progressListener.updateProgress(progress, id.toReadableString());
        } else {
            progressListener.updateProgress(progress);
        }
        checkId(id, allQNameToDefinitionMapping);
        checkXmlSchemaValidation(id);
        checkReferencedQNames(id, allQNameToDefinitionMapping);
        checkPropertiesValidation(id);
        if (id instanceof ServiceTemplateId) {
            checkServiceTemplate((ServiceTemplateId) id);
        }
        if (configuration.isCheckDocumentation()) {
            checkDocumentation(id);
        }
        checkPlainConformance(id, tempCsar);
        checkCsar(id, tempCsar, repository);
    }
}
Also used : Path(java.nio.file.Path) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13