Search in sources :

Example 1 with YamlArtifactsSynchronizer

use of org.eclipse.winery.repository.backend.YamlArtifactsSynchronizer in project winery by eclipse.

the class ServiceTemplateResource method setTopology.

@Override
public void setTopology(TTopologyTemplate topologyTemplate, String type) {
    // if we are in yaml mode, replacing the topology can result in yaml artifacts having to be deleted.
    if (Environments.getInstance().getRepositoryConfig().getProvider() == RepositoryConfigurationObject.RepositoryProvider.YAML) {
        try {
            YamlArtifactsSynchronizer synchronizer = new YamlArtifactsSynchronizer.Builder(RepositoryFactory.getRepository()).setOriginalTemplate(this.getServiceTemplate().getTopologyTemplate()).setNewTemplate(topologyTemplate).setServiceTemplateId((ServiceTemplateId) this.getId()).build();
            synchronizer.synchronizeNodeTemplates();
            synchronizer.synchronizeRelationshipTemplates();
        } catch (IOException e) {
            LOGGER.error("Failed to delete yaml artifact files from disk. Reason {}", e.getMessage());
        }
        if (topologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).anyMatch(nt -> nt.getRequirements().stream().anyMatch(req -> req.getRelationship() != null))) {
            // filter unused requirements
            // (1) get a list of requirement template ids
            // (2) filter requirement entry on node template if there is relations assigned
            Set<String> usedRelationshipTemplateIds = topologyTemplate.getRelationshipTemplates().stream().map(HasId::getId).collect(Collectors.toSet());
            topologyTemplate.getNodeTemplates().stream().filter(node -> node.getRequirements() != null).forEach(node -> node.getRequirements().removeIf(r -> !usedRelationshipTemplateIds.contains(r.getRelationship())));
        }
    }
    this.getServiceTemplate().setTopologyTemplate(topologyTemplate);
    this.cullElementReferences();
}
Also used : EdmmUtils(org.eclipse.winery.edmm.EdmmUtils) Produces(javax.ws.rs.Produces) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) PlansResource(org.eclipse.winery.repository.rest.resources.servicetemplates.plans.PlansResource) Date(java.util.Date) TopologyTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.TopologyTemplateResource) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) SelfServicePortalResource(org.eclipse.winery.repository.rest.resources.servicetemplates.selfserviceportal.SelfServicePortalResource) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) ThreatAssessment(org.eclipse.winery.model.threatmodeling.ThreatAssessment) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) Context(javax.ws.rs.core.Context) Collection(java.util.Collection) Set(java.util.Set) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) HasId(org.eclipse.winery.model.tosca.HasId) TInterface(org.eclipse.winery.model.tosca.TInterface) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) BoundaryDefinitionsResource(org.eclipse.winery.repository.rest.resources.servicetemplates.boundarydefinitions.BoundaryDefinitionsResource) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) Response(javax.ws.rs.core.Response) TPlan(org.eclipse.winery.model.tosca.TPlan) VersionUtils(org.eclipse.winery.common.version.VersionUtils) TCapability(org.eclipse.winery.model.tosca.TCapability) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) AbstractComponentInstanceResourceContainingATopology(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResourceContainingATopology) GET(javax.ws.rs.GET) YamlArtifactsSynchronizer(org.eclipse.winery.repository.backend.YamlArtifactsSynchronizer) Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) SimpleDateFormat(java.text.SimpleDateFormat) ApiResponses(io.swagger.annotations.ApiResponses) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TParameter(org.eclipse.winery.model.tosca.TParameter) InjectorReplaceOptions(org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions) ThreatModeling(org.eclipse.winery.model.threatmodeling.ThreatModeling) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Status(javax.ws.rs.core.Response.Status) Substitution(org.eclipse.winery.model.adaptation.substitution.Substitution) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) POST(javax.ws.rs.POST) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant) Environments(org.eclipse.winery.common.configuration.Environments) IOException(java.io.IOException) InjectRemoval(org.eclipse.winery.repository.splitting.InjectRemoval) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TTag(org.eclipse.winery.model.tosca.TTag) InjectorReplaceData(org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceData) EdmmResource(org.eclipse.winery.repository.rest.resources.edmm.EdmmResource) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) DASpecification(org.eclipse.winery.repository.driverspecificationandinjection.DASpecification) ApiResponse(io.swagger.annotations.ApiResponse) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) RepositoryConfigurationObject(org.eclipse.winery.common.configuration.RepositoryConfigurationObject) TOperation(org.eclipse.winery.model.tosca.TOperation) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DriverInjection(org.eclipse.winery.repository.driverspecificationandinjection.DriverInjection) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IHasName(org.eclipse.winery.repository.rest.resources._support.IHasName) YamlArtifactsSynchronizer(org.eclipse.winery.repository.backend.YamlArtifactsSynchronizer) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 URI (java.net.URI)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1