Search in sources :

Example 31 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class TableUtils method setLocalityGroups.

public static void setLocalityGroups(final AccumuloStore store) throws StoreException {
    final String tableName = store.getTableName();
    Map<String, Set<Text>> localityGroups = new HashMap<>();
    for (final String group : store.getSchema().getGroups()) {
        HashSet<Text> localityGroup = new HashSet<>();
        localityGroup.add(new Text(group));
        localityGroups.put(group, localityGroup);
    }
    LOGGER.info("Setting locality groups on table {}", tableName);
    try {
        store.getConnection().tableOperations().setLocalityGroups(tableName, localityGroups);
    } catch (final AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
        throw new StoreException(e.getMessage(), e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 32 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class AddElementsHandler method addElements.

private void addElements(final AddElements operation, final AccumuloStore store) throws OperationException {
    try {
        final Iterable<? extends Element> validatedElements;
        if (operation.isValidate()) {
            validatedElements = new ValidatedElements(operation.getInput(), store.getSchema(), operation.isSkipInvalidElements());
        } else {
            validatedElements = operation.getInput();
        }
        store.addElements(validatedElements);
    } catch (final StoreException e) {
        throw new OperationException("Failed to add elements", e);
    }
}
Also used : ValidatedElements(uk.gov.gchq.gaffer.store.ValidatedElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 33 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class PredefinedFederatedStore method initialise.

@Override
public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
    HashMapGraphLibrary.clear();
    CacheServiceLoader.shutdown();
    ExecutorService.shutdown();
    super.initialise(graphId, schema, properties);
    // Accumulo store just contains edges
    try {
        addGraphs(null, User.UNKNOWN_USER_ID, false, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_EDGES)).schema(new Schema.Builder().merge(schema.clone()).entities(Collections.emptyMap()).build()).properties(PROPERTIES).build());
        // Accumulo store just contains entities
        addGraphs(null, User.UNKNOWN_USER_ID, false, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_ENTITIES)).schema(new Schema.Builder().merge(schema.clone()).edges(Collections.emptyMap()).build()).properties(PROPERTIES).build());
    } catch (final StorageException e) {
        throw new StoreException(e.getMessage(), e);
    }
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 34 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class ParquetStore method setLatestSnapshot.

public void setLatestSnapshot(final long snapshot) throws StoreException {
    final Path snapshotPath = new Path(getDataDir(), getSnapshotPath(snapshot));
    try {
        if (!fs.exists(snapshotPath)) {
            throw new StoreException(String.format("Failed setting currentSnapshot: '%s' does not exist", snapshotPath.toString()));
        }
    } catch (final IOException e) {
        throw new StoreException("IOException checking Path: ", e);
    }
    LOGGER.info("Setting currentSnapshot to {} and reloading graph partitioner", snapshot);
    this.currentSnapshot = snapshot;
    loadGraphPartitioner();
}
Also used : Path(org.apache.hadoop.fs.Path) IOException(java.io.IOException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 35 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class ParquetStore method initialise.

private void initialise() throws IOException, StoreException {
    // If data directory is empty or does not exist then this is the first time the store has been created.
    final Path dataDirPath = new Path(getDataDir());
    if (!fs.exists(dataDirPath) || 0 == fs.listStatus(dataDirPath).length) {
        LOGGER.info("Data directory {} doesn't exist or is empty so initialising directory structure", dataDirPath);
        currentSnapshot = System.currentTimeMillis();
        LOGGER.info("Initialising snapshot id to {}", currentSnapshot);
        final Path snapshotPath = new Path(dataDirPath, getSnapshotPath(currentSnapshot));
        LOGGER.info("Creating snapshot directory {}", snapshotPath);
        fs.mkdirs(snapshotPath);
        LOGGER.info("Creating group directories under {}", snapshotPath);
        for (final String group : getSchema().getGroups()) {
            final Path groupDir = getGroupPath(group);
            fs.mkdirs(groupDir);
            LOGGER.info("Created directory {}", groupDir);
        }
        LOGGER.info("Creating group directories for reversed edges under {}", snapshotPath);
        for (final String group : getSchema().getEdgeGroups()) {
            final Path groupDir = getGroupPathForReversedEdges(group);
            fs.mkdirs(groupDir);
            LOGGER.info("Created directory {}", groupDir);
        }
        LOGGER.info("Creating GraphPartitioner with 0 split points for each group");
        graphPartitioner = new GraphPartitioner();
        for (final String group : getSchema().getGroups()) {
            graphPartitioner.addGroupPartitioner(group, new GroupPartitioner(group, new ArrayList<>()));
        }
        for (final String group : getSchema().getEdgeGroups()) {
            graphPartitioner.addGroupPartitionerForReversedEdges(group, new GroupPartitioner(group, new ArrayList<>()));
        }
        LOGGER.info("Writing GraphPartitioner to snapshot directory");
        final FSDataOutputStream dataOutputStream = fs.create(getGraphPartitionerPath());
        new GraphPartitionerSerialiser().write(graphPartitioner, dataOutputStream);
        dataOutputStream.close();
        LOGGER.info("Wrote GraphPartitioner to file {}", getGraphPartitionerPath().toString());
    } else {
        LOGGER.info("Data directory {} exists and is non-empty, validating a snapshot directory exists", dataDirPath);
        final FileStatus[] fileStatuses = fs.listStatus(dataDirPath, f -> f.getName().startsWith(SNAPSHOT + "="));
        final List<FileStatus> directories = Arrays.stream(fileStatuses).filter(f -> f.isDirectory()).collect(Collectors.toList());
        if (0 == directories.size()) {
            LOGGER.error("Data directory {} should contain a snapshot directory", dataDirPath);
            throw new StoreException("Data directory should contain a snapshot directory");
        }
        this.currentSnapshot = getLatestSnapshot();
        LOGGER.info("Latest snapshot directory in data directory {} is {}", dataDirPath, this.currentSnapshot);
        LOGGER.info("Verifying snapshot directory contains the correct directories");
        for (final String group : getSchema().getGroups()) {
            final Path groupDir = getGroupPath(group);
            if (!fs.exists(groupDir)) {
                LOGGER.error("Directory {} should exist", groupDir);
                throw new StoreException("Group directory " + groupDir + " should exist in snapshot directory " + getSnapshotPath(this.currentSnapshot));
            }
        }
        for (final String group : getSchema().getEdgeGroups()) {
            final Path groupDir = getGroupPathForReversedEdges(group);
            if (!fs.exists(groupDir)) {
                LOGGER.error("Directory {} should exist", groupDir);
                throw new StoreException("Group directory " + groupDir + " should exist in snapshot directory " + getSnapshotPath(this.currentSnapshot));
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) GroupPartitioner(uk.gov.gchq.gaffer.parquetstore.partitioner.GroupPartitioner) GraphPartitionerSerialiser(uk.gov.gchq.gaffer.parquetstore.partitioner.serialisation.GraphPartitionerSerialiser) GetElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.GetElementsHandler) InLineHyperLogLogPlusParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.InLineHyperLogLogPlusParquetSerialiser) Arrays(java.util.Arrays) BooleanParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.BooleanParquetSerialiser) DoubleParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.DoubleParquetSerialiser) FileSystem(org.apache.hadoop.fs.FileSystem) GetAdjacentIdsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.GetAdjacentIdsHandler) LoggerFactory(org.slf4j.LoggerFactory) ByteParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.ByteParquetSerialiser) FileStatus(org.apache.hadoop.fs.FileStatus) Element(uk.gov.gchq.gaffer.data.element.Element) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) FloatParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.FloatParquetSerialiser) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Configuration(org.apache.hadoop.conf.Configuration) TreeSetStringParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.TreeSetStringParquetSerialiser) Path(org.apache.hadoop.fs.Path) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) SerialisationFactory(uk.gov.gchq.gaffer.store.SerialisationFactory) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Partition(uk.gov.gchq.gaffer.parquetstore.partitioner.Partition) ImportJavaRDDOfElements(uk.gov.gchq.gaffer.spark.operation.javardd.ImportJavaRDDOfElements) GetDataFrameOfElements(uk.gov.gchq.gaffer.spark.operation.dataframe.GetDataFrameOfElements) SchemaUtils(uk.gov.gchq.gaffer.parquetstore.utils.SchemaUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Store(uk.gov.gchq.gaffer.store.Store) PRE_AGGREGATION_FILTERING(uk.gov.gchq.gaffer.store.StoreTrait.PRE_AGGREGATION_FILTERING) List(java.util.List) INGEST_AGGREGATION(uk.gov.gchq.gaffer.store.StoreTrait.INGEST_AGGREGATION) Entry(java.util.Map.Entry) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) StoreException(uk.gov.gchq.gaffer.store.StoreException) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) ORDERED(uk.gov.gchq.gaffer.store.StoreTrait.ORDERED) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) TypeSubTypeValueParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.TypeSubTypeValueParquetSerialiser) ImportJavaRDDOfElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.spark.ImportJavaRDDOfElementsHandler) GroupPartitioner(uk.gov.gchq.gaffer.parquetstore.partitioner.GroupPartitioner) ArrayList(java.util.ArrayList) CalculatePartitioner(uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.CalculatePartitioner) TypeValueParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.TypeValueParquetSerialiser) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IntegerParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.IntegerParquetSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) LongParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.LongParquetSerialiser) ImportRDDOfElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.spark.ImportRDDOfElementsHandler) Logger(org.slf4j.Logger) DateParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.DateParquetSerialiser) StringParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.StringParquetSerialiser) IOException(java.io.IOException) GetAllElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.GetAllElementsHandler) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FreqMapParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.FreqMapParquetSerialiser) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) GraphPartitionerSerialiser(uk.gov.gchq.gaffer.parquetstore.partitioner.serialisation.GraphPartitionerSerialiser) AddElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.AddElementsHandler) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetDataFrameOfElementsHandler(uk.gov.gchq.gaffer.parquetstore.operation.handler.spark.GetDataFrameOfElementsHandler) GraphPartitioner(uk.gov.gchq.gaffer.parquetstore.partitioner.GraphPartitioner) ImportRDDOfElements(uk.gov.gchq.gaffer.spark.operation.scalardd.ImportRDDOfElements) HashSetStringParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.HashSetStringParquetSerialiser) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) ArrayListStringParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.ArrayListStringParquetSerialiser) ShortParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.ShortParquetSerialiser) Collections(java.util.Collections) GraphPartitioner(uk.gov.gchq.gaffer.parquetstore.partitioner.GraphPartitioner) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Aggregations

StoreException (uk.gov.gchq.gaffer.store.StoreException)70 OperationException (uk.gov.gchq.gaffer.operation.OperationException)26 IOException (java.io.IOException)21 Path (org.apache.hadoop.fs.Path)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)11 HashSet (java.util.HashSet)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)9 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)9 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)9 ArrayList (java.util.ArrayList)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 Configuration (org.apache.hadoop.conf.Configuration)8 Test (org.junit.jupiter.api.Test)8 User (uk.gov.gchq.gaffer.user.User)8 Set (java.util.Set)6 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)6 FileSystem (org.apache.hadoop.fs.FileSystem)6