Search in sources :

Example 1 with CSARDirectoryCreationFailureException

use of alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException in project alien4cloud by alien4cloud.

the class CsarFileRepository method setRootPath.

@Required
@Value("${directories.alien}/${directories.csar_repository}")
public void setRootPath(String path) {
    this.rootPath = Paths.get(path).toAbsolutePath();
    if (!Files.isDirectory(rootPath)) {
        try {
            Files.createDirectories(rootPath);
            log.info("Alien Repository folder set to " + rootPath.toAbsolutePath());
        } catch (IOException e) {
            throw new CSARDirectoryCreationFailureException("Error while trying to create the CSAR repository <" + rootPath.toString() + ">. " + e.getMessage(), e);
        }
    } else {
        log.info("Alien Repository folder already created! " + rootPath.toAbsolutePath());
    }
}
Also used : CSARDirectoryCreationFailureException(alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException) IOException(java.io.IOException) Required(org.springframework.beans.factory.annotation.Required) Value(org.springframework.beans.factory.annotation.Value)

Example 2 with CSARDirectoryCreationFailureException

use of alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException in project alien4cloud by alien4cloud.

the class CsarFileRepository method storeCSAR.

@Override
public synchronized void storeCSAR(Csar csar, String yaml) {
    Path csarDirectoryPath = rootPath.resolve(csar.getName()).resolve(csar.getVersion());
    String realName = csar.getName().concat("-").concat(csar.getVersion()).concat("." + CSAR_EXTENSION);
    createCSARDirectory(csarDirectoryPath, realName);
    Path csarExpandedDirectoryPath = csarDirectoryPath.resolve(EXPANDED);
    try {
        Files.createDirectories(csarExpandedDirectoryPath);
        Path targetPath = csarExpandedDirectoryPath.resolve(csar.getYamlFilePath());
        try (BufferedWriter writer = Files.newBufferedWriter(targetPath)) {
            writer.write(yaml);
        }
    } catch (IOException e) {
        throw new CSARDirectoryCreationFailureException("Error while trying to create the CSAR directory <" + csarDirectoryPath.toString() + ">. " + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) CSARDirectoryCreationFailureException(alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

CSARDirectoryCreationFailureException (alien4cloud.component.repository.exception.CSARDirectoryCreationFailureException)2 IOException (java.io.IOException)2 BufferedWriter (java.io.BufferedWriter)1 Path (java.nio.file.Path)1 Required (org.springframework.beans.factory.annotation.Required)1 Value (org.springframework.beans.factory.annotation.Value)1