| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2014 Google Inc. | ||
| * | ||
| * Licensed 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 com.google.cloud.anviltop.hbase; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Strings; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
|
|
||
| /** | ||
| * Static methods to convert an instance of {@link Configuration} | ||
| * to a {@link AnviltopOptions} instance. | ||
| */ | ||
| public class AnvilTopOptionsFactory { | ||
| public static final String PROJECT_ID_KEY = "anviltop.project.id"; | ||
| public static final String API_ENDPOINT_KEY = "anviltop.endpoint.url"; | ||
|
|
||
| public static AnviltopOptions fromConfiguration(Configuration configuration) { | ||
| AnviltopOptions.Builder optionsBuilder = new AnviltopOptions.Builder(); | ||
|
|
||
| String projectId = configuration.get(PROJECT_ID_KEY); | ||
| Preconditions.checkArgument( | ||
| !Strings.isNullOrEmpty(projectId), | ||
| String.format("Project ID must be supplied via %s", PROJECT_ID_KEY)); | ||
| optionsBuilder.setProjectId(projectId); | ||
|
|
||
| String apiEndpoint = configuration.get(API_ENDPOINT_KEY); | ||
| Preconditions.checkArgument( | ||
| !Strings.isNullOrEmpty(apiEndpoint), | ||
| String.format("API endpoint URL must be supplied via %s", API_ENDPOINT_KEY)); | ||
| optionsBuilder.setApiEndpoint(apiEndpoint); | ||
|
|
||
| return optionsBuilder.build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright (c) 2014 Google Inc. | ||
| * | ||
| * Licensed 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 com.google.cloud.anviltop.hbase; | ||
|
|
||
| /** | ||
| * An immutable class providing access to configuration options for Anviltop. | ||
| */ | ||
| public class AnviltopOptions { | ||
|
|
||
| /** | ||
| * A mutable builder for AnviltopConnectionOptions. | ||
| */ | ||
| public static class Builder { | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhat's the advantage of including a Builder? I'm trying to see how this would make a developer's life easier.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityGetting a head start. I expect this to get close to https://github.com/GoogleCloudPlatform/bigdata-interop/blob/master/gcs/src/main/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageOptions.java in scope.
Sorry, something went wrong.
All reactions
|
||
| private String apiEndpoint = ""; | ||
| private String projectId = ""; | ||
|
|
||
| public Builder setApiEndpoint(String apiEndpoint) { | ||
| this.apiEndpoint = apiEndpoint; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setProjectId(String projectId) { | ||
| this.projectId = projectId; | ||
| return this; | ||
| } | ||
|
|
||
| public AnviltopOptions build() { | ||
| return new AnviltopOptions(this.apiEndpoint, this.projectId); | ||
| } | ||
| } | ||
|
|
||
| private final String apiEndpoint; | ||
| private final String projectId; | ||
|
|
||
| public AnviltopOptions(String apiEndpoint, String projectId) { | ||
| this.apiEndpoint = apiEndpoint; | ||
| this.projectId = projectId; | ||
| } | ||
|
|
||
| /** | ||
| * The API endpoint to connect to, including version information. | ||
| */ | ||
| public String getApiEndpoint() { | ||
| return apiEndpoint; | ||
| } | ||
|
|
||
| /** | ||
| * The project ID that table belong to. | ||
| */ | ||
| public String getProjectId() { | ||
| return projectId; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright (c) 2014 Google Inc. | ||
| * | ||
| * Licensed 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 com.google.cloud.anviltop.hbase.adapters; | ||
|
|
||
| import com.google.protobuf.GeneratedMessage.Builder; | ||
|
|
||
| import org.apache.hadoop.hbase.client.Operation; | ||
|
|
||
| /** | ||
| * An interface for adapters that will convert an HBase Operation into an Anviltop | ||
| * @param <T> The HBase operation type | ||
| * @param <U> The Anviltop message type | ||
| */ | ||
| public interface OperationAdapter<T extends Operation, U extends Builder> { | ||
|
|
||
| /** | ||
| * Adapt a single HBase Operation to a single Anviltop generated message. | ||
| * @param operation The HBase operation to convert. | ||
| * @return An equivalent Anviltop | ||
| */ | ||
| public U adapt(T operation); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright (c) 2014 Google Inc. | ||
| * | ||
| * Licensed 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 com.google.cloud.anviltop.hbase.adapters; | ||
|
|
||
| import com.google.bigtable.anviltop.AnviltopData; | ||
| import com.google.bigtable.anviltop.AnviltopData.RowMutation; | ||
| import com.google.bigtable.anviltop.AnviltopData.RowMutation.Mod; | ||
| import com.google.bigtable.anviltop.AnviltopData.RowMutation.Mod.SetCell; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.protobuf.ByteString; | ||
|
|
||
| import org.apache.hadoop.hbase.Cell; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.client.Put; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map.Entry; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Adapt an HBase Put Operation into an Anviltop RowMutation | ||
| */ | ||
| public class PutAdapter implements OperationAdapter<Put, RowMutation.Builder> { | ||
|
|
||
| public static final ByteString SEPARATOR_BYTE_STRING = ByteString.copyFromUtf8(":"); | ||
|
|
||
| @Override | ||
| public RowMutation.Builder adapt(Put operation) { | ||
| RowMutation.Builder result = AnviltopData.RowMutation.newBuilder(); | ||
| result.setRowKey(ByteString.copyFrom(operation.getRow())); | ||
|
|
||
| for (Entry<byte[], List<Cell>> entry : operation.getFamilyCellMap().entrySet()) { | ||
| ByteString familyByteString = ByteString.copyFrom(entry.getKey()); | ||
|
|
||
| for (Cell cell : entry.getValue()) { | ||
| Mod.Builder modBuilder = result.addModsBuilder(); | ||
| SetCell.Builder setCellBuilder = modBuilder.getSetCellBuilder(); | ||
|
|
||
| ByteString cellQualifierByteString = ByteString.copyFrom( | ||
| cell.getQualifierArray(), | ||
| cell.getQualifierOffset(), | ||
| cell.getQualifierLength()); | ||
|
|
||
| setCellBuilder.setColumnName( | ||
| ByteString.copyFrom( | ||
| ImmutableList.of( | ||
| familyByteString, | ||
| SEPARATOR_BYTE_STRING, | ||
| cellQualifierByteString))); | ||
|
|
||
| AnviltopData.Cell.Builder cellBuilder = setCellBuilder.getCellBuilder(); | ||
|
|
||
| if (cell.getTimestamp() != HConstants.LATEST_TIMESTAMP) { | ||
| long timestampMicros = TimeUnit.MILLISECONDS.toMicros(cell.getTimestamp()); | ||
| cellBuilder.setTimestampMicros(timestampMicros); | ||
| } | ||
|
|
||
| cellBuilder.setValue( | ||
| ByteString.copyFrom( | ||
| cell.getValueArray(), | ||
| cell.getValueOffset(), | ||
| cell.getValueLength())); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI assume this is just a stop-gap. What needs to be in place before we can remove this? The gRPC Java client?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCorrect.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.