|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright 2018-2019 The Feast Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package feast.jc.grpc; |
| 18 | + |
| 19 | +import com.google.api.gax.rpc.InvalidArgumentException; |
| 20 | +import com.google.protobuf.InvalidProtocolBufferException; |
| 21 | +import feast.auth.service.AuthorizationService; |
| 22 | +import feast.common.interceptors.GrpcMessageInterceptor; |
| 23 | +import feast.jc.config.FeastProperties; |
| 24 | +import feast.jc.service.JobService; |
| 25 | +import feast.proto.core.CoreServiceGrpc.CoreServiceImplBase; |
| 26 | +import feast.proto.core.CoreServiceProto.*; |
| 27 | +import feast.proto.core.FeatureSetProto.FeatureSet; |
| 28 | +import io.grpc.Status; |
| 29 | +import io.grpc.StatusRuntimeException; |
| 30 | +import io.grpc.stub.StreamObserver; |
| 31 | +import lombok.extern.slf4j.Slf4j; |
| 32 | +import net.devh.boot.grpc.server.service.GrpcService; |
| 33 | +import org.springframework.beans.factory.annotation.Autowired; |
| 34 | +import org.springframework.security.access.AccessDeniedException; |
| 35 | +import org.springframework.security.core.context.SecurityContextHolder; |
| 36 | + |
| 37 | +import java.util.List; |
| 38 | +import java.util.NoSuchElementException; |
| 39 | +import java.util.stream.Collectors; |
| 40 | + |
| 41 | +/** Implementation of the feast core GRPC service. */ |
| 42 | +@Slf4j |
| 43 | +@GrpcService(interceptors = {GrpcMessageInterceptor.class}) |
| 44 | +public class CoreServiceImpl extends CoreServiceImplBase { |
| 45 | + |
| 46 | + private final FeastProperties feastProperties; |
| 47 | + |
| 48 | + private JobService jobService; |
| 49 | + |
| 50 | + @Autowired |
| 51 | + public CoreServiceImpl( |
| 52 | + JobService jobService, |
| 53 | + FeastProperties feastProperties) { |
| 54 | + this.jobService = jobService; |
| 55 | + this.feastProperties = feastProperties; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void listIngestionJobs( |
| 60 | + ListIngestionJobsRequest request, |
| 61 | + StreamObserver<ListIngestionJobsResponse> responseObserver) { |
| 62 | + try { |
| 63 | + ListIngestionJobsResponse response = this.jobService.listJobs(request); |
| 64 | + responseObserver.onNext(response); |
| 65 | + responseObserver.onCompleted(); |
| 66 | + } catch (InvalidArgumentException e) { |
| 67 | + log.error("Received an invalid request on calling listIngestionJobs method:", e); |
| 68 | + responseObserver.onError( |
| 69 | + Status.INVALID_ARGUMENT.withDescription(e.getMessage()).withCause(e).asException()); |
| 70 | + } catch (Exception e) { |
| 71 | + log.error("Unexpected exception on calling listIngestionJobs method:", e); |
| 72 | + responseObserver.onError( |
| 73 | + Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException()); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public void restartIngestionJob( |
| 79 | + RestartIngestionJobRequest request, |
| 80 | + StreamObserver<RestartIngestionJobResponse> responseObserver) { |
| 81 | + try { |
| 82 | + RestartIngestionJobResponse response = this.jobService.restartJob(request); |
| 83 | + responseObserver.onNext(response); |
| 84 | + responseObserver.onCompleted(); |
| 85 | + } catch (NoSuchElementException e) { |
| 86 | + log.error( |
| 87 | + "Attempted to restart an nonexistent job on calling restartIngestionJob method:", e); |
| 88 | + responseObserver.onError( |
| 89 | + Status.NOT_FOUND.withDescription(e.getMessage()).withCause(e).asException()); |
| 90 | + } catch (UnsupportedOperationException e) { |
| 91 | + log.error("Recieved an unsupported request on calling restartIngestionJob method:", e); |
| 92 | + responseObserver.onError( |
| 93 | + |
| 94 | + Status.FAILED_PRECONDITION.withDescription(e.getMessage()).withCause(e).asException()); |
| 95 | + } catch (Exception e) { |
| 96 | + log.error("Unexpected exception on calling restartIngestionJob method:", e); |
| 97 | + responseObserver.onError( |
| 98 | + Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException()); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public void stopIngestionJob( |
| 104 | + StopIngestionJobRequest request, StreamObserver<StopIngestionJobResponse> |
| 105 | + responseObserver) { |
| 106 | + try { |
| 107 | + StopIngestionJobResponse response = this.jobService.stopJob(request); |
| 108 | + responseObserver.onNext(response); |
| 109 | + responseObserver.onCompleted(); |
| 110 | + } catch (NoSuchElementException e) { |
| 111 | + log.error("Attempted to stop an nonexistent job on calling stopIngestionJob method:", e); |
| 112 | + responseObserver.onError( |
| 113 | + Status.NOT_FOUND.withDescription(e.getMessage()).withCause(e).asException()); |
| 114 | + } catch (UnsupportedOperationException e) { |
| 115 | + log.error("Recieved an unsupported request on calling stopIngestionJob method:", e); |
| 116 | + responseObserver.onError( |
| 117 | + |
| 118 | + Status.FAILED_PRECONDITION.withDescription(e.getMessage()).withCause(e).asException()); |
| 119 | + } catch (Exception e) { |
| 120 | + log.error("Unexpected exception on calling stopIngestionJob method:", e); |
| 121 | + responseObserver.onError( |
| 122 | + Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException()); |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments