Search in sources :

Example 1 with OpsCasTarget

use of org.platformlayer.ops.cas.OpsCasTarget in project platformlayer by platformlayer.

the class DirectHostController method getCasStore.

@Override
public CasStore getCasStore() throws OpsException {
    // TODO: Getting the IP like this is evil
    NetworkPoint targetAddress;
    // if (host.getIpv6() != null) {
    // IpRange ipv6Range = IpV6Range.parse(host.getIpv6());
    // targetAddress = NetworkPoint.forPublicHostname(ipv6Range.getGatewayAddress());
    // } else {
    targetAddress = NetworkPoint.forPublicHostname(model.host);
    // }
    Machine machine = new OpaqueMachine(targetAddress);
    OpsTarget machineTarget = machine.getTarget(sshKeys.findOtherServiceKey(new ServiceType("machines-direct")));
    CasStoreInfo casStoreOptions = new CasStoreInfo(true);
    FilesystemCasStore store = new FilesystemCasStore(casStoreOptions, new OpsCasTarget(machineTarget));
    return store;
}
Also used : CasStoreInfo(org.platformlayer.cas.CasStoreInfo) OpsTarget(org.platformlayer.ops.OpsTarget) FilesystemCasStore(org.platformlayer.ops.cas.filesystem.FilesystemCasStore) ServiceType(org.platformlayer.ids.ServiceType) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) OpsCasTarget(org.platformlayer.ops.cas.OpsCasTarget) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine)

Example 2 with OpsCasTarget

use of org.platformlayer.ops.cas.OpsCasTarget 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

OpsCasTarget (org.platformlayer.ops.cas.OpsCasTarget)2 Md5Hash (com.fathomdb.hash.Md5Hash)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CasStoreInfo (org.platformlayer.cas.CasStoreInfo)1 CasStoreMap (org.platformlayer.cas.CasStoreMap)1 CasStoreObject (org.platformlayer.cas.CasStoreObject)1 ServiceType (org.platformlayer.ids.ServiceType)1 Command (org.platformlayer.ops.Command)1 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)1 Machine (org.platformlayer.ops.Machine)1 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)1 OpsException (org.platformlayer.ops.OpsException)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 FilesystemCasStore (org.platformlayer.ops.cas.filesystem.FilesystemCasStore)1 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)1 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)1