Search in sources :

Example 1 with CasStoreMap

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

the class DownloadFileByHash method getResolved.

public Md5Hash getResolved(OpsTarget target) throws OpsException {
    if (resolved == null) {
        if (hash == null) {
            if (specifier != null) {
                CasStoreMap casStores = cas.getCasStoreMap(target);
                resolved = (Md5Hash) casStores.resolve(specifier);
            }
        } else {
            resolved = hash;
        }
    }
    if (resolved == null) {
        throw new OpsException("Unable to resolve artifact: " + getHumanName());
    }
    return resolved;
}
Also used : CasStoreMap(org.platformlayer.cas.CasStoreMap) OpsException(org.platformlayer.ops.OpsException)

Example 2 with CasStoreMap

use of org.platformlayer.cas.CasStoreMap 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)

Example 3 with CasStoreMap

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

the class CasStoreHelper method getCasStoreMap.

public CasStoreMap getCasStoreMap(OpsTarget target) throws OpsException {
    // TODO: Reintroduce (some) caching?
    // if (this.casStores == null) {
    CasStoreMap casStores = new CasStoreMap();
    FilesystemCasStore filesystemCasStore = new FilesystemCasStore(new CasStoreInfo(false), new OpsCasTarget(target));
    casStores.addPrimary(filesystemCasStore);
    // TODO: Don't hard-code
    casStores.addSecondary(buildJenkins("http://192.168.131.14:8080/"));
    for (ProviderOf<CasStoreProvider> casStoreProvider : providers.listItemsProviding(CasStoreProvider.class)) {
        CasStore casStore = casStoreProvider.get().getCasStore();
        casStores.addSecondary(casStore);
        if (casStore.getOptions().isStaging()) {
            // Use this as a staging store i.e. we can upload files to here instead of to the VM
            casStores.addStagingStore(casStore);
        }
    }
    // }
    return casStores;
}
Also used : CasStoreMap(org.platformlayer.cas.CasStoreMap) CasStoreInfo(org.platformlayer.cas.CasStoreInfo) FilesystemCasStore(org.platformlayer.ops.cas.filesystem.FilesystemCasStore) JenkinsCasStore(org.platformlayer.ops.cas.jenkins.JenkinsCasStore) CasStore(org.platformlayer.cas.CasStore) FilesystemCasStore(org.platformlayer.ops.cas.filesystem.FilesystemCasStore)

Aggregations

CasStoreMap (org.platformlayer.cas.CasStoreMap)3 OpsException (org.platformlayer.ops.OpsException)2 Md5Hash (com.fathomdb.hash.Md5Hash)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CasStore (org.platformlayer.cas.CasStore)1 CasStoreInfo (org.platformlayer.cas.CasStoreInfo)1 CasStoreObject (org.platformlayer.cas.CasStoreObject)1 Command (org.platformlayer.ops.Command)1 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)1 OpsCasTarget (org.platformlayer.ops.cas.OpsCasTarget)1 FilesystemCasStore (org.platformlayer.ops.cas.filesystem.FilesystemCasStore)1 JenkinsCasStore (org.platformlayer.ops.cas.jenkins.JenkinsCasStore)1 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)1