Search in sources :

Example 1 with BuckCacheStoreRequest

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;
}
Also used : RuleKey(com.facebook.buck.artifact_cache.thrift.RuleKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BuckCacheStoreRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest) BuckCacheRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheRequest) PayloadInfo(com.facebook.buck.artifact_cache.thrift.PayloadInfo) ArtifactMetadata(com.facebook.buck.artifact_cache.thrift.ArtifactMetadata)

Example 2 with BuckCacheStoreRequest

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));
            }
        }
    }
}
Also used : BuckCacheStoreRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest) Request(okhttp3.Request) BuckCacheRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheRequest) BuckCacheFetchRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheFetchRequest) HttpResponse(com.facebook.buck.slb.HttpResponse) BuckCacheRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheRequest) IOException(java.io.IOException) ByteSource(com.google.common.io.ByteSource) BuckCacheStoreRequest(com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest) PayloadInfo(com.facebook.buck.artifact_cache.thrift.PayloadInfo) ArtifactMetadata(com.facebook.buck.artifact_cache.thrift.ArtifactMetadata) BuckCacheResponse(com.facebook.buck.artifact_cache.thrift.BuckCacheResponse)

Aggregations

ArtifactMetadata (com.facebook.buck.artifact_cache.thrift.ArtifactMetadata)2 BuckCacheRequest (com.facebook.buck.artifact_cache.thrift.BuckCacheRequest)2 BuckCacheStoreRequest (com.facebook.buck.artifact_cache.thrift.BuckCacheStoreRequest)2 PayloadInfo (com.facebook.buck.artifact_cache.thrift.PayloadInfo)2 BuckCacheFetchRequest (com.facebook.buck.artifact_cache.thrift.BuckCacheFetchRequest)1 BuckCacheResponse (com.facebook.buck.artifact_cache.thrift.BuckCacheResponse)1 RuleKey (com.facebook.buck.artifact_cache.thrift.RuleKey)1 HttpResponse (com.facebook.buck.slb.HttpResponse)1 ByteSource (com.google.common.io.ByteSource)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Request (okhttp3.Request)1