Search in sources :

Example 51 with IRepository

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();
}
Also used : MultiRepositoryManager(org.eclipse.winery.repository.filebased.MultiRepositoryManager) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 52 with IRepository

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();
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 53 with IRepository

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();
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant) LinkedHashMap(java.util.LinkedHashMap) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) Splitting(org.eclipse.winery.repository.splitting.Splitting) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) WineryVersion(org.eclipse.winery.common.version.WineryVersion) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 54 with IRepository

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);
}
Also used : Produces(javax.ws.rs.Produces) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) IdNames(org.eclipse.winery.model.ids.IdNames) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) Map(java.util.Map) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) TEntityTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.TEntityTemplateResource) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) IIdDetermination(org.eclipse.winery.repository.rest.resources._support.collections.IIdDetermination) Context(javax.ws.rs.core.Context) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) DeploymentArtifactsResource(org.eclipse.winery.repository.rest.resources.artifacts.DeploymentArtifactsResource) Objects(java.util.Objects) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) List(java.util.List) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Response(javax.ws.rs.core.Response) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) GenericDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.GenericDirectoryId) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) GenericFileResource(org.eclipse.winery.repository.rest.resources._support.GenericFileResource) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) FormParam(javax.ws.rs.FormParam) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) INodeTemplateResourceOrNodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResource) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) Date(java.util.Date) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) Response(javax.ws.rs.core.Response) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) IRepository(org.eclipse.winery.repository.backend.IRepository) SimpleDateFormat(java.text.SimpleDateFormat) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 55 with IRepository

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();
}
Also used : Server(org.eclipse.jetty.server.Server) AbstractFileBasedRepository(org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository) Prefs(org.eclipse.winery.repository.rest.Prefs) IRepository(org.eclipse.winery.repository.backend.IRepository)

Aggregations

IRepository (org.eclipse.winery.repository.backend.IRepository)75 TNodeType (org.eclipse.winery.model.tosca.TNodeType)29 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)27 IOException (java.io.IOException)24 QName (javax.xml.namespace.QName)24 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)22 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 HashMap (java.util.HashMap)15 LoggerFactory (org.slf4j.LoggerFactory)15 LinkedHashMap (java.util.LinkedHashMap)14 List (java.util.List)14 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)14 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)14 Collectors (java.util.stream.Collectors)13 POST (javax.ws.rs.POST)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13