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;
}
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);
}
}
Aggregations