Search in sources :

Example 1 with CasStoreObject

use of org.platformlayer.cas.CasStoreObject in project platformlayer by platformlayer.

the class DownloadFileByHash method uploadFile.

@Override
protected void uploadFile(OpsTarget target, File remoteFilePath) throws IOException, OpsException {
    target.mkdir(remoteFilePath.getParentFile());
    Md5Hash resolved = getResolved(target);
    CasStoreObject casObject;
    CasStoreMap casStoreMap = cas.getCasStoreMap(target);
    try {
        casObject = casStoreMap.findArtifact(new OpsCasTarget(target), resolved);
    } catch (Exception e) {
        throw new OpsException("Error while resolving artifact:" + getHumanName(), e);
    }
    if (url != null && casObject == null) {
        target.mkdir(remoteFilePath.getParentFile());
        CurlRequest curlRequest = new CurlRequest(url);
        curlRequest.bareRequest = true;
        CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);
        Command curlCommand = curlRequest.toCommand();
        curlCommand.addLiteral(">");
        curlCommand.addFile(remoteFilePath);
        curlCommand.setEnvironment(commandEnvironment);
        curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
        // TODO: Can we cache into CAS instead??
        log.info("Not found in CAS system; downloading directly: " + url);
        target.executeCommand(curlCommand);
    } else {
        if (casObject == null) {
            throw new OpsException("Unable to find artifact: " + getHumanName());
        }
        log.info("Doing a CAS copy from " + casObject + " to target");
        cas.copyObject(casStoreMap, casObject, new OpsCasTarget(target), remoteFilePath, true);
    }
}
Also used : CasStoreMap(org.platformlayer.cas.CasStoreMap) OpsException(org.platformlayer.ops.OpsException) CasStoreObject(org.platformlayer.cas.CasStoreObject) Command(org.platformlayer.ops.Command) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) CommandEnvironment(org.platformlayer.ops.CommandEnvironment) Md5Hash(com.fathomdb.hash.Md5Hash) OpsCasTarget(org.platformlayer.ops.cas.OpsCasTarget) URISyntaxException(java.net.URISyntaxException) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException)

Aggregations

Md5Hash (com.fathomdb.hash.Md5Hash)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CasStoreMap (org.platformlayer.cas.CasStoreMap)1 CasStoreObject (org.platformlayer.cas.CasStoreObject)1 Command (org.platformlayer.ops.Command)1 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)1 OpsException (org.platformlayer.ops.OpsException)1 OpsCasTarget (org.platformlayer.ops.cas.OpsCasTarget)1 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)1