Search in sources :

Example 21 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.

the class DefaultGraphFactory method createGraphBuilder.

@Override
public Graph.Builder createGraphBuilder() {
    final String storePropertiesPath = System.getProperty(SystemProperty.STORE_PROPERTIES_PATH);
    if (null == storePropertiesPath) {
        throw new SchemaException("The path to the Store Properties was not found in system properties for key: " + SystemProperty.STORE_PROPERTIES_PATH);
    }
    final StoreProperties storeProperties = StoreProperties.loadStoreProperties(storePropertiesPath);
    // Disable any operations required
    storeProperties.addOperationDeclarationPaths("disableOperations.json");
    final Graph.Builder builder = new Graph.Builder();
    builder.storeProperties(storeProperties);
    final String graphConfigPath = System.getProperty(SystemProperty.GRAPH_CONFIG_PATH);
    if (null != graphConfigPath) {
        builder.config(Paths.get(graphConfigPath));
    }
    for (final Path path : getSchemaPaths()) {
        builder.addSchema(path);
    }
    final String graphId = System.getProperty(SystemProperty.GRAPH_ID);
    if (null != graphId) {
        builder.graphId(graphId);
    }
    String graphLibraryClassName = System.getProperty(SystemProperty.GRAPH_LIBRARY_CLASS);
    if (null != graphLibraryClassName) {
        GraphLibrary library;
        try {
            library = Class.forName(graphLibraryClassName).asSubclass(GraphLibrary.class).newInstance();
        } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Error creating GraphLibrary class", e);
        }
        library.initialise(System.getProperty(SystemProperty.GRAPH_LIBRARY_CONFIG));
        builder.library(library);
    }
    final String graphHooksPath = System.getProperty(SystemProperty.GRAPH_HOOKS_PATH);
    if (null != graphHooksPath) {
        builder.addHooks(Paths.get(graphHooksPath));
    }
    return builder;
}
Also used : Path(java.nio.file.Path) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Graph(uk.gov.gchq.gaffer.graph.Graph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 22 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.

the class CoreKeyGroupByCombiner method init.

@Override
public void init(final SortedKeyValueIterator<Key, Value> source, final Map<String, String> options, final IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema", e);
    }
    LOGGER.debug("Initialising CoreKeyGroupByCombiner with schema {}", schema);
    try {
        view = View.fromJson(options.get(AccumuloStoreConstants.VIEW).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the view", e);
    }
    LOGGER.debug("Initialising CoreKeyGroupByCombiner with view {}", view);
    final String elementConverterClass = options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    try {
        elementConverter = Class.forName(elementConverterClass).asSubclass(AccumuloElementConverter.class).getConstructor(Schema.class).newInstance(schema);
        LOGGER.debug("Creating AccumuloElementConverter of class {}", elementConverterClass);
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to create element converter of the class name provided (" + elementConverterClass + ")", e);
    }
    final String encodedColumns = options.get(COLUMNS_OPTION);
    if (StringUtils.isNotEmpty(encodedColumns)) {
        aggregatedGroups = new ColumnSet(Lists.newArrayList(Splitter.on(",").split(encodedColumns)));
        LOGGER.debug("Setting aggregatedGroups to {}", aggregatedGroups);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ColumnSet(org.apache.accumulo.core.iterators.conf.ColumnSet) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)

Example 23 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.

the class SampleDataForSplitPointsMapper method setup.

@Override
protected void setup(final Context context) {
    super.setup(context);
    proportionToSample = context.getConfiguration().getFloat(AccumuloSampleDataForSplitPointsJobFactory.PROPORTION_TO_SAMPLE, 0.001f);
    final Schema schema;
    try {
        schema = Schema.fromJson(context.getConfiguration().get(AccumuloSampleDataForSplitPointsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise Store Schema from JSON", e);
    }
    try {
        elementConverter = Class.forName(context.getConfiguration().get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)).asSubclass(AccumuloElementConverter.class).getConstructor(Schema.class).newInstance(schema);
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new IllegalArgumentException("Element converter could not be created: " + context.getConfiguration().get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.

the class AggregatorIterator method init.

@Override
public void init(final SortedKeyValueIterator<Key, Value> source, final Map<String, String> options, final IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema from json", e);
    }
    LOGGER.debug("Initialising AggregatorIterator with schema {}", schema);
    final String elementConverterClass = options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    try {
        elementConverter = Class.forName(elementConverterClass).asSubclass(AccumuloElementConverter.class).getConstructor(Schema.class).newInstance(schema);
        LOGGER.debug("Creating AccumuloElementConverter of class {}", elementConverterClass);
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to create element converter of the class name provided (" + elementConverterClass + ")", e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)

Aggregations

SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)24 Schema (uk.gov.gchq.gaffer.store.schema.Schema)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Test (org.junit.jupiter.api.Test)8 Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)6 AggregationException (uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException)5 AccumuloElementConverter (uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)4 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)4 GetSchema (uk.gov.gchq.gaffer.store.operation.GetSchema)4 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)4 List (java.util.List)3 Graph (uk.gov.gchq.gaffer.graph.Graph)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2