use of com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest in project buck by facebook.
the class HybridPayloadGenerator method createStoreRequest.
private BuckCacheRequest createStoreRequest() {
BuckCacheRequest cacheRequest = new BuckCacheRequest();
cacheRequest.setType(BuckCacheRequestType.STORE);
BuckCacheStoreRequest storeRequest = new BuckCacheStoreRequest();
ArtifactMetadata metadata = new ArtifactMetadata();
RuleKey ruleKeyOne = new RuleKey();
ruleKeyOne.setHashString(STORE_RULE_KEY_ONE);
RuleKey ruleKeyTwo = new RuleKey();
ruleKeyTwo.setHashString(STORE_RULE_KEY_TWO);
List<RuleKey> ruleKeys = new ArrayList<>();
ruleKeys.add(ruleKeyOne);
ruleKeys.add(ruleKeyTwo);
metadata.setRuleKeys(ruleKeys);
Map<String, String> metadataMap = new HashMap<>();
metadataMap.put(METDATA_KEY_ONE, METDATA_VALUE_ONE);
metadataMap.put(METDATA_KEY_TWO, METDATA_VALUE_TWO);
metadata.setRuleKeys(ruleKeys);
metadata.setMetadata(metadataMap);
List<PayloadInfo> payloadInfos = new ArrayList<>();
PayloadInfo payloadInfo = new PayloadInfo();
payloadInfo.setSizeBytes(PAYLOAD_ONE_BYTES.length);
payloadInfos.add(payloadInfo);
storeRequest.setMetadata(metadata);
cacheRequest.setStoreRequest(storeRequest);
cacheRequest.setPayloads(payloadInfos);
return cacheRequest;
}
use of com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest in project buck by facebook.
the class ThriftArtifactCache method storeImpl.
@Override
protected void storeImpl(final ArtifactInfo info, final Path file, final HttpArtifactCacheEvent.Finished.Builder eventBuilder) throws IOException {
final ByteSource artifact = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return projectFilesystem.newFileInputStream(file);
}
};
BuckCacheStoreRequest storeRequest = new BuckCacheStoreRequest();
ArtifactMetadata artifactMetadata = infoToMetadata(info, artifact, repository, scheduleType, distributedBuildModeEnabled);
storeRequest.setMetadata(artifactMetadata);
PayloadInfo payloadInfo = new PayloadInfo();
long artifactSizeBytes = artifact.size();
payloadInfo.setSizeBytes(artifactSizeBytes);
BuckCacheRequest cacheRequest = new BuckCacheRequest();
cacheRequest.addToPayloads(payloadInfo);
cacheRequest.setType(BuckCacheRequestType.STORE);
cacheRequest.setStoreRequest(storeRequest);
if (LOG.isVerboseEnabled()) {
LOG.verbose(String.format("Storing artifact with metadata: [%s].", ThriftUtil.thriftToDebugJson(artifactMetadata)));
}
final ThriftArtifactCacheProtocol.Request request = ThriftArtifactCacheProtocol.createRequest(PROTOCOL, cacheRequest, artifact);
Request.Builder builder = toOkHttpRequest(request);
eventBuilder.getStoreBuilder().setRequestSizeBytes(request.getRequestLengthBytes());
try (HttpResponse httpResponse = storeClient.makeRequest(hybridThriftEndpoint, builder)) {
if (httpResponse.statusCode() != 200) {
throw new IOException(String.format("Failed to store cache artifact with HTTP status code [%d:%s] " + " to url [%s] for build target [%s] that has size [%d] bytes.", httpResponse.statusCode(), httpResponse.statusMessage(), httpResponse.requestUrl(), info.getBuildTarget().orElse(null), artifactSizeBytes));
}
try (ThriftArtifactCacheProtocol.Response response = ThriftArtifactCacheProtocol.parseResponse(PROTOCOL, httpResponse.getBody())) {
BuckCacheResponse cacheResponse = response.getThriftData();
if (!cacheResponse.isWasSuccessful()) {
reportFailure("Failed to store artifact with thriftErrorMessage=[%s] " + "url=[%s] artifactSizeBytes=[%d]", response.getThriftData().getErrorMessage(), httpResponse.requestUrl(), artifactSizeBytes);
}
eventBuilder.getStoreBuilder().setArtifactContentHash(storeRequest.getMetadata().artifactPayloadMd5);
eventBuilder.getStoreBuilder().setWasStoreSuccessful(cacheResponse.isWasSuccessful());
if (LOG.isDebugEnabled()) {
LOG.debug("Debug info for cache store request: artifactMetadata=[%s] response=[%s]", ThriftUtil.thriftToDebugJson(artifactMetadata), ThriftUtil.thriftToDebugJson(cacheResponse));
}
}
}
}
Aggregations