use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class Splitting method getInputParamListofIncomingRelationshipTemplates.
public List<TParameter> getInputParamListofIncomingRelationshipTemplates(TTopologyTemplate topologyTemplate, List<TRelationshipTemplate> listOfIncomingRelationshipTemplates) {
List<TParameter> listOfInputs = new ArrayList<>();
IRepository repo = RepositoryFactory.getRepository();
for (TRelationshipTemplate incomingRelationshipTemplate : listOfIncomingRelationshipTemplates) {
TNodeTemplate incomingNodetemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
NodeTypeId incomingNodeTypeId = new NodeTypeId(incomingNodetemplate.getType());
TNodeType incomingNodeType = repo.getElement(incomingNodeTypeId);
List<TInterface> incomingNodeTypeInterfaces = incomingNodeType.getInterfaces();
RelationshipTypeId incomingRelationshipTypeId = new RelationshipTypeId(incomingRelationshipTemplate.getType());
if (!incomingNodeTypeInterfaces.isEmpty()) {
TInterface relevantInterface = null;
List<TInterface> connectionInterfaces = incomingNodeTypeInterfaces.stream().filter(tInterface -> tInterface.getIdFromIdOrNameField().contains("connection")).collect(Collectors.toList());
if (connectionInterfaces.size() > 1) {
TNodeTemplate targetNodeTemplate = ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
for (TInterface tInterface : connectionInterfaces) {
int separator = tInterface.getIdFromIdOrNameField().lastIndexOf("/");
String prefixRelation = tInterface.getIdFromIdOrNameField().substring(separator + 1);
if (targetNodeTemplate.getName() != null && targetNodeTemplate.getName().toLowerCase().contains(prefixRelation.toLowerCase())) {
relevantInterface = tInterface;
}
}
} else {
relevantInterface = connectionInterfaces.get(0);
}
if (relevantInterface != null) {
for (TOperation tOperation : relevantInterface.getOperations()) {
List<TParameter> inputParameters = tOperation.getInputParameters();
if (inputParameters != null) {
listOfInputs.addAll(inputParameters);
}
}
}
}
}
return listOfInputs;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class Splitting method matchTopologyOfServiceTemplate.
/**
* Splits the topology template of the given service template. Creates a new service template with "-split" suffix
* as id. Any existing "-split" service template will be deleted. Matches the split topology template to the cloud
* providers according to the target labels. Creates a new service template with "-matched" suffix as id. Any
* existing "-matched" service template will be deleted.
*
* @param id of the ServiceTemplate switch should be split and matched to cloud providers
* @return id of the ServiceTemplate which contains the matched topology
*/
public ServiceTemplateId matchTopologyOfServiceTemplate(ServiceTemplateId id) throws Exception {
long start = System.currentTimeMillis();
IRepository repository = RepositoryFactory.getRepository();
TServiceTemplate serviceTemplate = repository.getElement(id);
TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
/*
Get all open requirements and the basis type of the required capability type
Two different basis types are distinguished:
"Container" which means a hostedOn injection is required
"Endpoint" which means a connectsTo injection is required
*/
Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = getOpenRequirementsAndMatchingBasisCapabilityTypeNames(topologyTemplate);
// Output check
LOGGER.debug("Matching for ServiceTemplate with ID: {}", id.getQName());
for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
LOGGER.debug("Open Requirement: {}", req.getId());
LOGGER.debug("Matching basis type: {}", requirementsAndMatchingBasisCapabilityTypes.get(req));
}
TTopologyTemplate matchedConnectedTopologyTemplate;
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
// set default target labels if they are not yet set
if (!hasTargetLabels(topologyTemplate)) {
LOGGER.debug("Target labels are not set for all NodeTemplates. Using default target labels.");
topologyTemplate.getNodeTemplates().forEach(t -> ModelUtilities.setTargetLabel(t, "*"));
}
TTopologyTemplate matchedHostsTopologyTemplate = hostMatchingWithDefaultHostSelection(topologyTemplate);
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(matchedHostsTopologyTemplate);
} else {
matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
}
} else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(topologyTemplate);
} else {
throw new SplittingException("No open Requirements which can be matched");
}
TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate;
// Start additional functionality Driver Injection
if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) {
daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate);
}
// End additional functionality Driver Injection
// create wrapper service template
ServiceTemplateId matchedServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(id, "matched"), false);
RepositoryFactory.getRepository().forceDelete(matchedServiceTemplateId);
RepositoryFactory.getRepository().flagAsExisting(matchedServiceTemplateId);
repository.flagAsExisting(matchedServiceTemplateId);
TServiceTemplate matchedServiceTemplate = new TServiceTemplate();
matchedServiceTemplate.setName(matchedServiceTemplateId.getXmlId().getDecoded());
matchedServiceTemplate.setId(matchedServiceTemplate.getName());
matchedServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
matchedServiceTemplate.setTopologyTemplate(daSpecifiedTopology);
LOGGER.debug("Persisting...");
repository.setElement(matchedServiceTemplateId, matchedServiceTemplate);
LOGGER.debug("Persisted.");
long duration = System.currentTimeMillis() - start;
LOGGER.debug("Execution Time in millisec: " + duration + "ms");
return matchedServiceTemplateId;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class Splitting method resolveTopologyTemplate.
/**
*/
public void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId) throws SplittingException, IOException {
IRepository repository = RepositoryFactory.getRepository();
TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
List<TRequirement> openRequirements = getOpenRequirements(topologyTemplate);
for (TRequirement requirement : openRequirements) {
QName requiredCapTypeQName = getRequiredCapabilityTypeQNameOfRequirement(requirement);
List<TNodeTemplate> nodesWithMatchingCapability = topologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().stream().anyMatch(c -> c.getType().equals(requiredCapTypeQName))).collect(Collectors.toList());
if (!nodesWithMatchingCapability.isEmpty() && nodesWithMatchingCapability.size() == 1) {
TCapability matchingCapability = nodesWithMatchingCapability.get(0).getCapabilities().stream().filter(c -> c.getType().equals(requiredCapTypeQName)).findFirst().get();
TRelationshipType matchingRelationshipType = getMatchingRelationshipType(requirement, matchingCapability);
if (matchingRelationshipType != null) {
addMatchingRelationshipTemplateToTopologyTemplate(topologyTemplate, matchingRelationshipType, requirement, matchingCapability);
} else {
throw new SplittingException("No suitable relationship type found for matching");
}
}
}
repository.setElement(serviceTemplateId, serviceTemplate);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class YamlCsarImporter method storeDefs.
private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
IRepository repo = RepositoryFactory.getRepository();
FromCanonical converter = null;
if (repo instanceof GitBasedRepository) {
GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
converter = new FromCanonical((YamlRepository) wrapper.getRepository());
} else if (repo instanceof YamlRepository) {
converter = new FromCanonical((YamlRepository) repo);
}
if (Objects.nonNull(converter)) {
YamlWriter writer = new YamlWriter();
writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class PolicyWrapper method extractProperty.
private Object extractProperty() {
IRepository repository = RepositoryFactory.getRepository();
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getType());
TPolicyType policyType = repository.getElement(policyTypeId);
LinkedHashMap<String, String> properties = ModelUtilities.getPropertiesKV(policy);
if (properties == null) {
// FIXME This needs to correctly deal with YamlProperties as well!!
return null;
}
for (Map.Entry<String, String> property : properties.entrySet()) {
if (property.getKey().equals(propertyKey)) {
String type = getType(policyType, propertyKey);
return cast(property.getValue(), type);
}
}
return null;
}
Aggregations