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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations