Search in sources :

Example 1 with UnresolvableArtifactException

use of alien4cloud.deployment.exceptions.UnresolvableArtifactException in project alien4cloud by alien4cloud.

the class ArtifactProcessorService method processLocalArtifact.

private void processLocalArtifact(AbstractArtifact artifact) {
    try {
        Path csarPath = repository.getExpandedCSAR(artifact.getArchiveName(), artifact.getArchiveVersion());
        Path resolvedPath = csarPath.resolve(artifact.getArtifactRef());
        if (!Files.exists(resolvedPath)) {
            throw new UnresolvableArtifactException("Artifact could not be accessed " + artifact);
        }
        artifact.setArtifactPath(resolvedPath.toString());
    } catch (NotFoundException e) {
        throw new UnresolvableArtifactException("Artifact could not be found " + artifact, e);
    }
}
Also used : Path(java.nio.file.Path) UnresolvableArtifactException(alien4cloud.deployment.exceptions.UnresolvableArtifactException) NotFoundException(alien4cloud.exception.NotFoundException)

Example 2 with UnresolvableArtifactException

use of alien4cloud.deployment.exceptions.UnresolvableArtifactException in project alien4cloud by alien4cloud.

the class ArtifactProcessorService method processArtifact.

private void processArtifact(AbstractArtifact artifact) {
    if (ArtifactRepositoryConstants.ALIEN_ARTIFACT_REPOSITORY.equals(artifact.getArtifactRepository())) {
        artifact.setArtifactPath(artifactRepository.resolveFile(artifact.getArtifactRef()).toString());
        return;
    }
    URL artifactURL = null;
    if (artifact.getRepositoryName() == null) {
        // Short notation
        try {
            // Test if it's an URL
            artifactURL = new URL(artifact.getArtifactRef());
        } catch (MalformedURLException e) {
            if (log.isDebugEnabled()) {
                log.debug("Processing local artifact {}", artifact);
            }
            // Not a URL then must be a relative path to a file inside the csar
            processLocalArtifact(artifact);
            return;
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Processing remote artifact {}", artifact);
    }
    String artifactPath = resolveArtifact(artifact);
    if (artifactPath == null) {
        if (artifactURL != null) {
            try (InputStream artifactStream = artifactURL.openStream()) {
                // In a best effort try in a generic manner to obtain the artifact
                Path tempPath = Files.createTempFile(tempDir, "url-artifact", FilenameUtils.getExtension(artifact.getArtifactRef()));
                artifactPath = tempPath.toString();
                Files.copy(artifactStream, tempPath, StandardCopyOption.REPLACE_EXISTING);
            } catch (IOException e) {
                throw new UnresolvableArtifactException("Artifact could not be found " + artifact, e);
            }
        } else {
            throw new UnresolvableArtifactException("Artifact could not be found " + artifact);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Remote artifact from {} resolved to {}", artifact.getArtifactRef(), artifactPath);
    }
    artifact.setArtifactPath(artifactPath);
}
Also used : Path(java.nio.file.Path) UnresolvableArtifactException(alien4cloud.deployment.exceptions.UnresolvableArtifactException) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

UnresolvableArtifactException (alien4cloud.deployment.exceptions.UnresolvableArtifactException)2 Path (java.nio.file.Path)2 NotFoundException (alien4cloud.exception.NotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1