Search in sources :

Example 11 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class CopybaraGenerator method generateOriginFilesConfig.

public String generateOriginFilesConfig() {
    SortedSet<DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds();
    return allDefinitionsChildIds.stream().filter(id -> {
        RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, Constants.LICENSE_FILE_NAME);
        if (!repository.exists(repositoryFileReference)) {
            return false;
        }
        try (InputStream inputStream = repository.newInputStream(repositoryFileReference)) {
            // we put the whole license file text into a string and check if it starts with "Apache License" after
            // trimming it
            final String licenceString = "Apache License";
            String fileAsString = IOUtils.toString(inputStream);
            return fileAsString.trim().startsWith(licenceString);
        } catch (IOException e) {
            LOGGER.error("Could not create input stream for {}", repositoryFileReference.toString(), e);
            return false;
        }
    }).map(id -> BackendUtils.getPathInsideRepo(id)).collect(Collectors.joining("**\",\n        \"", "origin_files = glob([\"README.md\", \"LICENSE\", \"", "**\"]),"));
}
Also used : Logger(org.slf4j.Logger) SortedSet(java.util.SortedSet) Files(java.nio.file.Files) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Constants(org.eclipse.winery.common.Constants) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) IOUtils(org.apache.commons.io.IOUtils) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) StringJoiner(java.util.StringJoiner) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Path(java.nio.file.Path) InputStream(java.io.InputStream) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 12 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class ScriptPluginTest method downloadDeps.

@Test
void downloadDeps() throws Exception {
    this.setRevisionTo("origin/plain");
    ScriptPlugin scriptPlugin = new ScriptPlugin();
    QName originalQName = QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypeimplementations}MySQL-DBMS_5.7-Install-w1");
    SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = scriptPlugin.downloadDependenciesBasedOnArtifact(originalQName, RepositoryFactory.getRepository());
    ArtifactTemplateId selfContainedId = new ArtifactTemplateId("http://opentosca.org/add/management/to/instances/nodetypeimplementations", "MySQL-DBMS_5.7-Install-w1-selfContained-w1-wip1", false);
    ArtifactTemplateId generatedDAId = new ArtifactTemplateId("http://opentosca.org/add/management/to/instances/nodetypeimplementations", "MySQL-DBMS_5.7-Install-w1-mysql-server-5.7-DA-w1-wip1", false);
    assertNotNull(generatedArtifacts);
    assertEquals(1, generatedArtifacts.deploymentArtifactsToAdd.size());
    assertEquals(generatedDAId.getQName(), generatedArtifacts.deploymentArtifactsToAdd.get(0));
    assertEquals(ToscaBaseTypes.archiveArtifactType, repository.getElement(generatedDAId).getType());
    assertEquals(originalQName, generatedArtifacts.artifactToReplaceQName);
    assertEquals(selfContainedId.getQName(), generatedArtifacts.selfContainedArtifactQName);
    assertTrue(repository.exists(selfContainedId));
    assertTrue(repository.exists(generatedDAId));
    ArtifactTemplateFilesDirectoryId installScriptId = new ArtifactTemplateFilesDirectoryId(selfContainedId);
    SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(installScriptId);
    assertEquals(1, containedFiles.size());
    String targetFileStr = IOUtils.toString(repository.newInputStream(containedFiles.first()), StandardCharsets.UTF_8);
    assertEquals("#!/bin/sh\n" + "sudo sh -c \"echo '127.0.0.1' $(hostname) >> /etc/hosts\";\n" + "sudo apt-get update -qq;\n" + "# disables setting the root password with gui, root password etc. will be set in the configure.sh\n" + "export DEBIAN_FRONTEND=noninteractive;\n" + "#//Self-contained CSAR//mysql-server-5.7.tar.gz\n" + "innerCsarRoot=$(find ~ -maxdepth 1 -path \"*.csar\");\n" + "IFS=';' read -ra NAMES <<< \"$DAs\";\n" + "for k in \"${NAMES[@]}\"; do\n" + "    IFS=',' read -ra PATH <<< \"$k\"; \n" + "    selfContainedDaDirName=$(/usr/bin/sudo /usr/bin/dirname $innerCsarRoot${PATH[1]})\n" + "    selfContainedDaName=$(/usr/bin/sudo /usr/bin/basename $innerCsarRoot${PATH[1]})\n" + "    selfContainedExtractFolderName=\"${selfContainedDaName%.*}\"\n" + "    if [[ \"${PATH[1]}\" == *mysql-server-5.7.tar.gz ]];\n" + "    then\n" + "        /usr/bin/sudo mkdir -p \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n" + "        /bin/tar  -xvzf \"$selfContainedDaDirName/$selfContainedDaName\" -C \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n" + "        break\n" + "    fi\n" + "done\n" + "export DEBIAN_FRONTEND=noninteractive\n" + "/usr/bin/sudo -E /usr/bin/dpkg -i -R -E -B \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n", targetFileStr);
    ArtifactTemplateFilesDirectoryId daId = new ArtifactTemplateFilesDirectoryId(generatedDAId);
    containedFiles = repository.getContainedFiles(daId);
    assertEquals(1, containedFiles.size());
    assertEquals("mysql-server-5.7.tar.gz", containedFiles.first().getFileName());
}
Also used : ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 13 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class OptionResource method onDelete.

@Override
public Response onDelete() {
    // delete icon and plan model reference ...
    // delete icon
    // we use the URL stored in the data instead of the generated URL to be compatible with manually edits
    RepositoryFileReference ref = new RepositoryFileReference(this.ssmdId, this.o.getIconUrl());
    try {
        RepositoryFactory.getRepository().forceDelete(ref);
    } catch (IOException e) {
        OptionResource.LOGGER.error("Could not remove file", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    // delete plan input
    // we use the URL stored in the data instead of the generated URL to be compatible with manually edits
    ref = new RepositoryFileReference(this.ssmdId, this.o.getPlanInputMessageUrl());
    try {
        RepositoryFactory.getRepository().forceDelete(ref);
    } catch (IOException e) {
        OptionResource.LOGGER.error("Could not remove file", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    // after deleting files, continue with list deletion
    return super.onDelete();
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException)

Example 14 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class SelfServicePortalResource method putImage.

@PUT
@Path("image.jpg")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response putImage(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) {
    try {
        SelfServiceMetaDataUtils.ensureDataXmlExists(RepositoryFactory.getRepository(), this.id);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
    RepositoryFileReference ref = new RepositoryFileReference(this.id, "image.jpg");
    Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
    if (StringUtils.isEmpty(this.application.getImageUrl())) {
        this.application.setImageUrl("image.jpg");
        persist();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 15 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class PlanFileResource method getFileRef.

/**
 * Extracts the file reference from plan's planModelReference
 */
@Nullable
private RepositoryFileReference getFileRef() {
    if (this.plan.getPlanModelReference() == null) {
        return null;
    }
    String reference = this.plan.getPlanModelReference().getReference();
    if (reference == null) {
        return null;
    }
    File f = new File(reference);
    return new RepositoryFileReference(this.planId, f.getName());
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) File(java.io.File) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)81 IOException (java.io.IOException)33 Path (java.nio.file.Path)26 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)17 QName (javax.xml.namespace.QName)14 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)14 InputStream (java.io.InputStream)13 ArrayList (java.util.ArrayList)12 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)12 IRepository (org.eclipse.winery.repository.backend.IRepository)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 PlanId (org.eclipse.winery.model.ids.elements.PlanId)10 PlansId (org.eclipse.winery.model.ids.elements.PlansId)10 XmlId (org.eclipse.winery.model.ids.XmlId)9 Test (org.junit.jupiter.api.Test)9 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)8 MediaType (org.apache.tika.mime.MediaType)7 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)7 BufferedInputStream (java.io.BufferedInputStream)6 HashMap (java.util.HashMap)6