use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class ModelUtilitiesTest method instantiateNodeTemplate.
// endregion
@Test
public void instantiateNodeTemplate() throws Exception {
this.setRevisionTo("origin/plain");
IRepository repository = RepositoryFactory.getRepository();
TNodeType nodeType = repository.getElement(new NodeTypeId(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes}Ubuntu_16.04-w1")));
TNodeTemplate nodeTemplate = ModelUtilities.instantiateNodeTemplate(nodeType);
assertNotNull(nodeTemplate);
assertNotNull(nodeTemplate.getProperties());
assertEquals(8, ((TEntityTemplate.WineryKVProperties) nodeTemplate.getProperties()).getKVProperties().size());
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class RestUtils method releaseVersion.
public static Response releaseVersion(DefinitionsChildId releasableComponent) {
ResourceResult result = new ResourceResult();
final IRepository repository = RepositoryFactory.getRepository();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasableComponent, repository);
if (version.isReleasable()) {
if (repository instanceof GitBasedRepository) {
try {
freezeVersion(releasableComponent);
version.setWorkInProgressVersion(0);
String newId = releasableComponent.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(releasableComponent.getClass(), releasableComponent.getNamespace().getDecoded(), newId, false);
result = duplicate(releasableComponent, newComponent);
BackendUtils.commit(newComponent, "Release", repository);
} catch (GitAPIException e) {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.BAD_REQUEST);
}
return result.getResponse();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class RestUtils method rename.
public static ResourceResult rename(DefinitionsChildId oldId, DefinitionsChildId newId) {
ResourceResult result = new ResourceResult();
IRepository repo = RepositoryFactory.getRepository();
WineryVersion version = oldId.getVersion();
DefinitionsChildId id = newId;
if (version.toString().length() > 0) {
// ensure that the version isn't changed by the user
String componentName = newId.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
id = BackendUtils.getDefinitionsChildId(oldId.getClass(), newId.getNamespace().getDecoded(), componentName, false);
}
// If a definition was not committed yet, it is renamed, otherwise duplicate the definition.
if (repo.hasChangesInFile(oldId)) {
try {
repo.rename(oldId, id);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
result.setStatus(Status.INTERNAL_SERVER_ERROR);
result.setMessage(e.getMessage());
return result;
}
} else {
result = duplicate(oldId, id);
if (result.isSuccess()) {
result = freezeVersion(id);
}
}
URI uri = RestUtils.getAbsoluteURI(id);
result.setUri(uri);
result.setStatus(Status.CREATED);
return result;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class ServiceTemplateResource method createNewPlaceholderVersion.
@POST()
@Path("createplaceholderversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createNewPlaceholderVersion() throws IOException {
LOGGER.debug("Creating new placeholder version of Service Template {}...", this.getId());
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
WineryVersion newVersion = new WineryVersion("gdm-" + version.toString(), 1, 1);
IRepository repository = RepositoryFactory.getRepository();
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
if (repository.exists(newId)) {
repository.forceDelete(newId);
}
ResourceResult response = RestUtils.duplicate(id, newId);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
LOGGER.debug("Created Service Template {}", newId.getQName());
return response.getResponse();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class ServiceTemplateResource method generatePlaceholdersWithCapability.
@POST
@Path("placeholder/generator")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response generatePlaceholdersWithCapability() {
Splitting splitting = new Splitting();
TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
if (topologyTemplate == null) {
return Response.notModified().build();
}
try {
// get all open requirements and the respective node templates with open requirements
Map<TRequirement, TNodeTemplate> requirementsAndItsNodeTemplates = splitting.getOpenRequirementsAndItsNodeTemplate(topologyTemplate);
IRepository repo = RepositoryFactory.getRepository();
// iterate over all open requirements
for (Map.Entry<TRequirement, TNodeTemplate> entry : requirementsAndItsNodeTemplates.entrySet()) {
List<PropertyDefinitionKV> propertyDefinitionKVList = new ArrayList<>();
LinkedHashMap<String, String> placeholderNodeTemplateProperties = new LinkedHashMap<>();
// current node template with open requirements
TNodeTemplate nodeTemplateWithOpenReq = entry.getValue();
// get type of node template with open requirements
NodeTypeId id = new NodeTypeId(nodeTemplateWithOpenReq.getType());
TNodeType sourceNodeType = repo.getElement(id);
List<TInterface> sourceNodeTypeInterfaces = sourceNodeType.getInterfaces();
if (sourceNodeTypeInterfaces != null) {
for (TInterface tInterface : sourceNodeTypeInterfaces) {
// TODO: make this more safe
for (TOperation tOperation : tInterface.getOperations()) {
List<TParameter> inputParameters = tOperation.getInputParameters();
if (inputParameters != null) {
for (TParameter inputParameter : inputParameters) {
generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
}
}
}
}
}
List<TRelationshipTemplate> incomingRelationshipTemplates = ModelUtilities.getIncomingRelationshipTemplates(topologyTemplate, nodeTemplateWithOpenReq);
List<TParameter> inputParameters = splitting.getInputParamListofIncomingRelationshipTemplates(topologyTemplate, incomingRelationshipTemplates);
for (TParameter inputParameter : inputParameters) {
String prefixTARGET = "TARGET_";
String prefixSOURCE = "SOURCE_";
String inputParamName = inputParameter.getName();
if (inputParamName.contains(prefixTARGET)) {
inputParamName = inputParamName.replaceAll(prefixTARGET, "");
}
if (inputParamName.contains(prefixSOURCE)) {
inputParamName = inputParamName.replaceAll(prefixSOURCE, "");
}
inputParameter.setName(inputParamName);
generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
}
// get required capability type of open requirement
QName capabilityType = splitting.getRequiredCapabilityTypeQNameOfRequirement(entry.getKey());
// create new placeholder node type
TNodeType placeholderNodeType = splitting.createPlaceholderNodeType(nodeTemplateWithOpenReq.getName());
QName placeholderQName = new QName(placeholderNodeType.getTargetNamespace(), placeholderNodeType.getName());
WinerysPropertiesDefinition winerysPropertiesDefinition = sourceNodeType.getWinerysPropertiesDefinition();
// add properties definition
placeholderNodeType.setProperties(null);
if (winerysPropertiesDefinition != null) {
winerysPropertiesDefinition.setPropertyDefinitions(propertyDefinitionKVList);
placeholderNodeType.setProperties(winerysPropertiesDefinition);
String namespace = placeholderNodeType.getWinerysPropertiesDefinition().getNamespace();
NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
if (!namespaceManager.hasPermanentProperties(namespace)) {
namespaceManager.addPermanentNamespace(namespace);
}
}
NodeTypeId placeholderId = new NodeTypeId(placeholderQName);
// check if placeholder node type exists
if (repo.exists(placeholderId)) {
// delete and create new
RestUtils.delete(placeholderId);
}
repo.setElement(placeholderId, placeholderNodeType);
// create placeholder node template
TNodeTemplate placeholderNodeTemplate = splitting.createPlaceholderNodeTemplate(topologyTemplate, nodeTemplateWithOpenReq.getName(), placeholderQName);
// create capability of placeholder node template
TCapability capa = splitting.createPlaceholderCapability(topologyTemplate, capabilityType);
ModelUtilities.setPropertiesKV(placeholderNodeTemplate, placeholderNodeTemplateProperties);
if (placeholderNodeTemplate.getCapabilities() == null) {
placeholderNodeTemplate.setCapabilities(new ArrayList<>());
}
placeholderNodeTemplate.getCapabilities().add(capa);
for (Map.Entry<QName, String> targetLocation : nodeTemplateWithOpenReq.getOtherAttributes().entrySet()) {
placeholderNodeTemplate.getOtherAttributes().put(targetLocation.getKey(), targetLocation.getValue());
}
// add placeholder to node template and connect with source node template with open requirements
topologyTemplate.addNodeTemplate(placeholderNodeTemplate);
ModelUtilities.createRelationshipTemplateAndAddToTopology(nodeTemplateWithOpenReq, placeholderNodeTemplate, ToscaBaseTypes.hostedOnRelationshipType, topologyTemplate);
}
LOGGER.debug("PERSISTING");
RestUtils.persist(this);
LOGGER.debug("PERSISTED");
String responseId = this.getServiceTemplate().getId();
return Response.ok().entity(responseId).build();
} catch (Exception e) {
LOGGER.error("Could not fetch requirements and capabilities", e);
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}
Aggregations