View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.security.access;
20  
21  import java.io.IOException;
22
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.hbase.Coprocessor;
26  import org.apache.hadoop.hbase.CoprocessorEnvironment;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
29  import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
30  import org.apache.hadoop.hbase.protobuf.RequestConverter;
31  import org.apache.hadoop.hbase.protobuf.ResponseConverter;
32  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.BulkLoadHFileRequest;
33  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CleanupBulkLoadRequest;
34  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CleanupBulkLoadResponse;
35  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.PrepareBulkLoadRequest;
36  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.PrepareBulkLoadResponse;
37  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
38  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
39  import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.SecureBulkLoadHFilesRequest;
40  import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.SecureBulkLoadHFilesResponse;
41  import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.SecureBulkLoadService;
42  import org.apache.hadoop.hbase.regionserver.SecureBulkLoadManager;
43  import com.google.protobuf.RpcCallback;
44  import com.google.protobuf.RpcController;
45  import com.google.protobuf.Service;
46
47  /**
48   * Coprocessor service for bulk loads in secure mode.
49   * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
50   */
51  @InterfaceAudience.Private
52  @Deprecated
53  public class SecureBulkLoadEndpoint extends SecureBulkLoadService
54      implements CoprocessorService, Coprocessor {
55
56    public static final long VERSION = 0L;
57
58    private static final Log LOG = LogFactory.getLog(SecureBulkLoadEndpoint.class);
59
60    private RegionCoprocessorEnvironment env;
61
62    @Override
63    public void start(CoprocessorEnvironment env) {
64      this.env = (RegionCoprocessorEnvironment)env;
65      LOG.warn("SecureBulkLoadEndpoint is deprecated. It will be removed in future releases.");
66      LOG.warn("Secure bulk load has been integrated into HBase core.");
67    }
68
69    @Override
70    public void stop(CoprocessorEnvironment env) throws IOException {
71    }
72
73    @Override
74    public void prepareBulkLoad(RpcController controller, PrepareBulkLoadRequest request,
75        RpcCallback<PrepareBulkLoadResponse> done) {
76      try {
77        SecureBulkLoadManager secureBulkLoadManager =
78            this.env.getRegionServerServices().getSecureBulkLoadManager();
79        String bulkToken = secureBulkLoadManager.prepareBulkLoad(this.env.getRegion(), request);
80        done.run(PrepareBulkLoadResponse.newBuilder().setBulkToken(bulkToken).build());
81      } catch (IOException e) {
82        ResponseConverter.setControllerException(controller, e);
83      }
84      done.run(null);
85    }
86
87    @Override
88    public void cleanupBulkLoad(RpcController controller, CleanupBulkLoadRequest request,
89        RpcCallback<CleanupBulkLoadResponse> done) {
90      try {
91        SecureBulkLoadManager secureBulkLoadManager =
92            this.env.getRegionServerServices().getSecureBulkLoadManager();
93        secureBulkLoadManager.cleanupBulkLoad(this.env.getRegion(), request);
94        done.run(CleanupBulkLoadResponse.newBuilder().build());
95      } catch (IOException e) {
96        ResponseConverter.setControllerException(controller, e);
97      }
98      done.run(null);
99    }
100
101   @Override
102   public void secureBulkLoadHFiles(RpcController controller, SecureBulkLoadHFilesRequest request,
103       RpcCallback<SecureBulkLoadHFilesResponse> done) {
104     boolean loaded = false;
105     try {
106       SecureBulkLoadManager secureBulkLoadManager =
107           this.env.getRegionServerServices().getSecureBulkLoadManager();
108       BulkLoadHFileRequest bulkLoadHFileRequest = ConvertSecureBulkLoadHFilesRequest(request);
109       loaded = secureBulkLoadManager.secureBulkLoadHFiles(this.env.getRegion(), bulkLoadHFileRequest);
110     } catch (IOException e) {
111       ResponseConverter.setControllerException(controller, e);
112     }
113     done.run(SecureBulkLoadHFilesResponse.newBuilder().setLoaded(loaded).build());
114   }
115
116   private BulkLoadHFileRequest ConvertSecureBulkLoadHFilesRequest(
117       SecureBulkLoadHFilesRequest request) {
118     BulkLoadHFileRequest.Builder bulkLoadHFileRequest = BulkLoadHFileRequest.newBuilder();
119     RegionSpecifier region =
120         RequestConverter.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, this.env
121             .getRegionInfo().getRegionName());
122
123     bulkLoadHFileRequest.setRegion(region).setFsToken(request.getFsToken())
124         .setBulkToken(request.getBulkToken()).setAssignSeqNum(request.getAssignSeqNum())
125         .addAllFamilyPath(request.getFamilyPathList());
126     return bulkLoadHFileRequest.build();
127   }
128
129   @Override
130   public Service getService() {
131     return this;
132   }
133 }