From commits-return-77378-archive-asf-public=cust-asf.ponee.io@beam.apache.org Tue Jun 12 21:02:06 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 3D83918078A for ; Tue, 12 Jun 2018 21:02:05 +0200 (CEST) Received: (qmail 46341 invoked by uid 500); 12 Jun 2018 19:02:04 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 46332 invoked by uid 99); 12 Jun 2018 19:02:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jun 2018 19:02:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D75FBC036E for ; Tue, 12 Jun 2018 19:02:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.5 X-Spam-Level: X-Spam-Status: No, score=-109.5 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id KIJjKiMBynXP for ; Tue, 12 Jun 2018 19:02:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id DFF635F4A0 for ; Tue, 12 Jun 2018 19:02:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id EDDF7E0D0F for ; Tue, 12 Jun 2018 19:02:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 6407F2109C for ; Tue, 12 Jun 2018 19:02:00 +0000 (UTC) Date: Tue, 12 Jun 2018 19:02:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: commits@beam.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Work logged] (BEAM-4291) ArtifactRetrievalService that retrieves artifacts from a distributed filesystem MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/BEAM-4291?focusedWorklogId=111217&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-111217 ] ASF GitHub Bot logged work on BEAM-4291: ---------------------------------------- Author: ASF GitHub Bot Created on: 12/Jun/18 19:01 Start Date: 12/Jun/18 19:01 Worklog Time Spent: 10m Work Description: jkff commented on a change in pull request #5584: [BEAM-4291] Add distributed artifact retrieval URL: https://github.com/apache/beam/pull/5584#discussion_r194853410 ########## File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/artifact/DfsArtifactRetrievalService.java ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.beam.runners.fnexecution.artifact; + + +import com.google.common.collect.ImmutableList; +import com.google.protobuf.ByteString; +import io.grpc.stub.StreamObserver; +import java.io.InputStream; +import java.io.InvalidObjectException; +import java.nio.ByteBuffer; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import org.apache.beam.model.jobmanagement.v1.ArtifactApi; +import org.apache.beam.model.jobmanagement.v1.ArtifactRetrievalServiceGrpc; +import org.apache.beam.sdk.io.FileSystems; +import org.apache.beam.sdk.io.fs.ResourceId; + +/** + * An {@link ArtifactRetrievalService} that uses distributed file systems as its backing storage. + */ +public class DfsArtifactRetrievalService + extends ArtifactRetrievalServiceGrpc.ArtifactRetrievalServiceImplBase + implements ArtifactRetrievalService { + + private static int artifactChunkSizeBytes = 2000000; // 2MB + + public static DfsArtifactRetrievalService create() { + return new DfsArtifactRetrievalService(); + } + + @Override + public void getManifest( + ArtifactApi.GetManifestRequest request, + StreamObserver responseObserver) { + try { + ArtifactApi.ProxyManifest proxyManifest = loadManifestFrom(request.getRetrievalToken()); + ArtifactApi.GetManifestResponse response = + ArtifactApi.GetManifestResponse + .newBuilder() + .setManifest(proxyManifest.getManifest()) + .build(); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } catch (Exception e) { + responseObserver.onError(e); + } + } + + @Override + public void getArtifact( + ArtifactApi.GetArtifactRequest request, + StreamObserver responseObserver) { + try { + ArtifactApi.ProxyManifest proxyManifest = loadManifestFrom(request.getRetrievalToken()); + // validate that name is contained in manifest and location list + boolean containsArtifactName = + ImmutableList.copyOf(proxyManifest.getManifest().getArtifactList()) + .stream() + .anyMatch(metadata -> metadata.getName().equals(request.getName())); + if (!containsArtifactName) { + throw new ArtifactNotFoundException(request.getName()); + } + // look for file at URI specified by proxy manifest location + ImmutableList locationList = + ImmutableList.copyOf(proxyManifest.getLocationList()); + ArtifactApi.ProxyManifest.Location location = + locationList + .stream() + .filter(loc -> loc.getName().equals(request.getName())) + .findFirst() + .orElseThrow(() -> new ArtifactNotFoundException(request.getName())); + ResourceId artifactResourceId = + FileSystems.matchNewResource(location.getUri(), false /* is directory */); + ReadableByteChannel artifactByteChannel = FileSystems.open(artifactResourceId); + ByteBuffer byteBuffer = ByteBuffer.allocate(artifactChunkSizeBytes); + while (artifactByteChannel.read(byteBuffer) > -1) { + ByteString data = ByteString.copyFrom(byteBuffer); + byteBuffer.clear(); + ArtifactApi.ArtifactChunk artifactChunk = + ArtifactApi.ArtifactChunk.newBuilder().setData(data).build(); + responseObserver.onNext(artifactChunk); + } + responseObserver.onCompleted(); + } catch (Exception e) { + responseObserver.onError(e); + } + + } + + @Override + public void close() throws Exception { + + } + + private ArtifactApi.ProxyManifest loadManifestFrom(String retrievalToken) throws Exception { + // look for file at $retrieval_token/$manifestName + ResourceId manifestResourceId = + FileSystems.matchNewResource(retrievalToken, false /* is directory */); + InputStream manifestStream = Channels.newInputStream(FileSystems.open(manifestResourceId)); Review comment: This needs a try-with-resources too ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 111217) Time Spent: 3h 40m (was: 3.5h) > ArtifactRetrievalService that retrieves artifacts from a distributed filesystem > ------------------------------------------------------------------------------- > > Key: BEAM-4291 > URL: https://issues.apache.org/jira/browse/BEAM-4291 > Project: Beam > Issue Type: Sub-task > Components: runner-core > Reporter: Eugene Kirpichov > Assignee: Axel Magnuson > Priority: Major > Time Spent: 3h 40m > Remaining Estimate: 0h > > In agreement with how they are staged in BEAM-4290. -- This message was sent by Atlassian JIRA (v7.6.3#76005)