use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class RepositoryAdminResource method deleteRepository.
/**
* Deletes given repository
*
* @param name of repository to delete.
*/
@DELETE
@Path("repositories/{repository}")
public Response deleteRepository(@PathParam("repository") String name) {
String repositoryUrl = "";
if (RepositoryFactory.getRepository() instanceof MultiRepository) {
IRepository gitRepo;
MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
for (RepositoryProperties repo : multiRepositoryManager.getRepositoriesAsList()) {
if (repo.getName().equals(name)) {
repositoryUrl = repo.getUrl();
break;
}
}
for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
gitRepo = repo;
if (gitRepo instanceof GitBasedRepository) {
if (((GitBasedRepository) gitRepo).getRepositoryUrl() != null) {
if (((GitBasedRepository) gitRepo).getRepositoryUrl().equals(repositoryUrl)) {
((GitBasedRepository) gitRepo).forceClear();
((MultiRepository) RepositoryFactory.getRepository()).removeRepository(repositoryUrl);
break;
}
}
}
}
}
return Response.ok().build();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class EntityTypeResource method getListOfAllInstances.
/**
* Used by children to implement getListOfAllInstances()
*/
protected SortedSet<Select2OptGroup> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) throws RepositoryCorruptException {
Select2DataWithOptGroups data = new Select2DataWithOptGroups();
IRepository repo = RepositoryFactory.getRepository();
Collection<? extends DefinitionsChildId> instanceIds = repo.getAllElementsReferencingGivenType(clazz, this.id.getQName());
for (DefinitionsChildId instanceId : instanceIds) {
String groupText = instanceId.getNamespace().getDecoded();
String text = BackendUtils.getName(instanceId, repo);
data.add(groupText, instanceId.getQName().toString(), text);
}
return data.asSortedSet();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class ServiceTemplateResource method createPlaceholderSubstituteVersion.
@Path("placeholdersubstitution")
@POST()
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createPlaceholderSubstituteVersion() throws IOException, SplittingException {
TTopologyTemplate originTopologyTemplate = this.getServiceTemplate().getTopologyTemplate();
if (originTopologyTemplate == null) {
return Response.notModified().build();
}
List<TTag> tagsOfServiceTemplate = this.getServiceTemplate().getTags();
List<OTParticipant> participants = originTopologyTemplate.getParticipants();
String participantId = "";
List<TTag> newTagList = new ArrayList<>();
for (TTag tagOfServiceTemplate : tagsOfServiceTemplate) {
if (tagOfServiceTemplate.getName().equals("participant")) {
participantId = tagOfServiceTemplate.getValue();
newTagList.add(tagOfServiceTemplate);
} else if (!tagOfServiceTemplate.getName().equals("choreography")) {
newTagList.add(tagOfServiceTemplate);
}
}
final String finalParticipantId = participantId;
List<String> nodeTemplatesWithNewHost = new ArrayList<>();
for (TNodeTemplate tNodeTemplate : originTopologyTemplate.getNodeTemplates()) {
// Multiple participants can be annotated on one node template
Optional<String> nodeOwners = ModelUtilities.getParticipant(tNodeTemplate);
if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
for (TRelationshipTemplate tRelationshipTemplate : ModelUtilities.getIncomingRelationshipTemplates(originTopologyTemplate, tNodeTemplate)) {
nodeTemplatesWithNewHost.add(ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(originTopologyTemplate, tRelationshipTemplate).getId());
}
}
}
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
WineryVersion newVersion = new WineryVersion("_substituted_" + version.toString(), 1, 1);
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
IRepository repo = RepositoryFactory.getRepository();
if (repo.exists(newId)) {
repo.forceDelete(newId);
}
ResourceResult response = RestUtils.duplicate(id, newId);
TServiceTemplate newServiceTemplate = repo.getElement(newId);
newServiceTemplate.setTopologyTemplate(BackendUtils.clone(originTopologyTemplate));
newServiceTemplate.getTopologyTemplate().setParticipants(participants);
Splitting splitting = new Splitting();
Map<String, List<TTopologyTemplate>> resultList = splitting.getHostingInjectionOptions(BackendUtils.clone(newServiceTemplate.getTopologyTemplate()));
for (Map.Entry<String, List<TTopologyTemplate>> entry : resultList.entrySet()) {
Optional<String> nodeOwners = ModelUtilities.getParticipant(newServiceTemplate.getTopologyTemplate().getNodeTemplate(entry.getKey()));
if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
if (nodeTemplatesWithNewHost.contains(entry.getKey()) && !resultList.get(entry.getKey()).isEmpty()) {
Map<String, TTopologyTemplate> choiceTopologyTemplate = new LinkedHashMap<>();
choiceTopologyTemplate.put(entry.getKey(), entry.getValue().get(0));
splitting.injectNodeTemplates(newServiceTemplate.getTopologyTemplate(), choiceTopologyTemplate, InjectRemoval.REMOVE_REPLACED);
for (TNodeTemplate injectNodeTemplate : choiceTopologyTemplate.get(entry.getKey()).getNodeTemplates()) {
injectNodeTemplate.getOtherAttributes().put(QNAME_PARTICIPANT, finalParticipantId);
}
}
}
}
String choreoValue = splitting.calculateChoreographyTag(newServiceTemplate.getTopologyTemplate().getNodeTemplates(), participantId);
TTag choreoTag = new TTag();
choreoTag.setName("choreography");
choreoTag.setValue(choreoValue);
newTagList.add(choreoTag);
newServiceTemplate.setTags(newTagList);
repo.setElement(newId, newServiceTemplate);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
return response.getResponse();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class NodeTemplateResource method createStateElement.
@POST
@Path("state")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createStateElement(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @Context UriInfo uriInfo) {
LOGGER.debug("Received state artifact for Node Template {} with ID {}", this.nodeTemplate.getName(), this.nodeTemplate.getId());
LOGGER.debug("Artifact file name is {} and is {} bytes big.", fileDetail.getFileName(), fileDetail.getSize());
// ensure that the artifact type exists.
IRepository repo = RepositoryFactory.getRepository();
repo.getElement(new ArtifactTypeId(OpenToscaBaseTypes.stateArtifactType));
// create DA
Optional<TDeploymentArtifact> stateDeploymentArtifact = this.getDeploymentArtifacts().getDeploymentArtifacts().stream().filter(artifact -> artifact.getArtifactType() != null).filter(artifact -> artifact.getArtifactType().equals(OpenToscaBaseTypes.stateArtifactType)).findFirst();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
TDeploymentArtifact deploymentArtifact = new TDeploymentArtifact.Builder("state", OpenToscaBaseTypes.stateArtifactType).build();
String componentVersion = dateFormat.format(new Date());
ArtifactTemplateId newArtifactTemplateId = new ArtifactTemplateId("http://opentosca.org/artifacttemplates", this.getServiceTemplateResource().getServiceTemplate().getName() + "-" + this.nodeTemplate.getId() + "-State" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + componentVersion + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1", false);
LOGGER.debug("Created Artifact Template of Type \"State\" called {}", newArtifactTemplateId.getQName());
// if there is already a state artifact, update the file
if (stateDeploymentArtifact.isPresent()) {
LOGGER.debug("Updating the state DA of the Node Template...");
deploymentArtifact = stateDeploymentArtifact.get();
// create new ArtifactTemplate version
ArtifactTemplateId oldArtifactTemplateId = new ArtifactTemplateId(deploymentArtifact.getArtifactRef());
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(oldArtifactTemplateId, repo);
WineryVersion newWineryVersion = VersionUtils.getNewWineryVersion(versions);
newWineryVersion.setWorkInProgressVersion(0);
newWineryVersion.setComponentVersion(componentVersion);
newArtifactTemplateId = (ArtifactTemplateId) VersionSupport.getDefinitionInTheGivenVersion(oldArtifactTemplateId, newWineryVersion);
} else {
LOGGER.debug("Creating the state DA of the Node Template...");
List<TDeploymentArtifact> list = this.nodeTemplate.getDeploymentArtifacts();
if (Objects.isNull(list)) {
list = new ArrayList<>();
this.nodeTemplate.setDeploymentArtifacts(list);
}
list.add(deploymentArtifact);
}
new ArtifactTemplatesResource().onJsonPost(new QNameWithTypeApiData(newArtifactTemplateId.getQName().getLocalPart(), newArtifactTemplateId.getQName().getNamespaceURI(), OpenToscaBaseTypes.stateArtifactType.toString()));
LOGGER.debug("Attaching the new Artifact...");
deploymentArtifact.setArtifactRef(newArtifactTemplateId.getQName());
Response response = new ArtifactTemplateResource(newArtifactTemplateId).getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo, this.nodeTemplate.getId() + ".state");
if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
LOGGER.debug("Could not create artifact file! Response was {}", response);
return response;
}
LOGGER.debug("Persisting now...");
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class WineryUsingHttpServer method main.
public static void main(String[] args) throws Exception {
// Initialize repository
new Prefs(true);
Server server = createHttpServer();
server.start();
IRepository repository = RepositoryFactory.getRepository();
if (repository instanceof AbstractFileBasedRepository) {
LOGGER.debug("Using path " + repository.getRepositoryRoot());
} else {
LOGGER.debug("Repository is not filebased");
}
// Waits until server is finished.
// Will never happen, thus user has to press Ctrl+C.
// See also https://stackoverflow.com/a/14981621/873282.
server.join();
}
Aggregations