cshannon commented on code in PR #4415: URL: https://github.com/apache/accumulo/pull/4415#discussion_r1554223938
########## test/src/main/java/org/apache/accumulo/test/ample/TestAmple.java: ########## @@ -0,0 +1,212 @@ +/* + * 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 + * + * https://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.accumulo.test.ample; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedMap; + +import org.apache.accumulo.core.client.AccumuloClient; +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.ConditionalWriter; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.Scanner; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.admin.NewTableConfiguration; +import org.apache.accumulo.core.client.admin.TabletAvailability; +import org.apache.accumulo.core.client.admin.TabletInformation; +import org.apache.accumulo.core.client.admin.TimeType; +import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.conf.SiteConfiguration; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.TableId; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.dataImpl.KeyExtent; +import org.apache.accumulo.core.iterators.user.WholeRowIterator; +import org.apache.accumulo.core.metadata.AccumuloTable; +import org.apache.accumulo.core.metadata.schema.Ample; +import org.apache.accumulo.core.metadata.schema.Ample.DataLevel; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection; +import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily; +import org.apache.accumulo.core.metadata.schema.MetadataTime; +import org.apache.accumulo.core.metadata.schema.TabletsMetadata; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.util.ColumnFQ; +import org.apache.accumulo.manager.Manager; +import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl; +import org.apache.accumulo.server.ServerContext; +import org.apache.accumulo.server.metadata.ConditionalTabletsMutatorImpl; +import org.apache.accumulo.server.metadata.ServerAmpleImpl; +import org.apache.accumulo.server.metadata.TabletsMutatorImpl; +import org.apache.hadoop.io.Text; +import org.easymock.EasyMock; + +import com.google.common.base.Preconditions; +import com.google.common.collect.MoreCollectors; + +public class TestAmple { + + public static Ample create(ServerContext context, Map<DataLevel,String> tables) { + return new TestServerAmpleImpl(context, tables); + } + + public static class TestServerAmpleImpl extends ServerAmpleImpl { + + private final Map<DataLevel,String> tables; + + public TestServerAmpleImpl(ServerContext context, final Map<DataLevel,String> tables) { + super(context); + this.tables = Map.copyOf(tables); + Preconditions.checkArgument(tables.containsKey(DataLevel.USER)); + } + + @Override + public TabletsMutator mutateTablets() { + return new TabletsMutatorImpl(getContext()) { + @Override + protected String getMetadataTableName() { + return TestServerAmpleImpl.this.getMetadataTableName(); + } + }; + } + + @Override + public TabletsMetadata.TableOptions readTablets() { + return TabletsMetadata.builder(getContext(), getMetadataTableName()); + } + + /** + * Create default metadata for a Table + * + * TODO: Add a way to pass in options for config + * + * @param tableId The id of the table to create metadata for + */ + public void createMetadata(TableId tableId) { + try (var tabletsMutator = mutateTablets()) { + var extent = new KeyExtent(tableId, null, null); + var tabletMutator = tabletsMutator.mutateTablet(extent); + String dirName = ServerColumnFamily.DEFAULT_TABLET_DIR_NAME; + tabletMutator.putPrevEndRow(extent.prevEndRow()); + tabletMutator.putDirName(dirName); + tabletMutator.putTime(new MetadataTime(0, TimeType.MILLIS)); + tabletMutator.putTabletAvailability(TabletAvailability.HOSTED); + tabletMutator.mutate(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Create metadata for a table by copying existing metadata for the table from the metadata + * table in an existing Accumulo instance + * + * TODO: Add config parents (such as a way to include/exclude what is copied, etc) Review Comment: I like this idea, I just pushed up a new commit that implements it https://github.com/apache/accumulo/pull/4415/commits/e6b199eed5cf2ae1dc20a2d7873a2e49843bb964 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org