Search in sources :

Example 71 with StoreProperties

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

the class AbstractGraphLibraryTest method shouldNotOverwriteSchemaWithClashingName.

@Test
public void shouldNotOverwriteSchemaWithClashingName() throws Exception {
    final String clashingId = "clashingId";
    byte[] entitySchema = new Builder().entity("e1", new SchemaEntityDefinition.Builder().property("p1", "string").build()).type("string", String.class).build().toJson(true);
    byte[] edgeSchema = new Builder().edge("e1", new SchemaEdgeDefinition.Builder().property("p1", "string").build()).type("string", String.class).build().toJson(true);
    graphLibrary.addSchema(clashingId, Schema.fromJson(entitySchema));
    assertThatExceptionOfType(OverwritingException.class).isThrownBy(() -> graphLibrary.add("graph", clashingId, Schema.fromJson(edgeSchema), TEST_PROPERTIES_ID, new StoreProperties())).withMessageContaining("schemaId clashingId already exists with a different schema");
    Schema schemaFromLibrary = graphLibrary.getSchema(clashingId);
    assertTrue(JsonUtil.equals(entitySchema, schemaFromLibrary.toJson(true)));
    assertFalse(JsonUtil.equals(schemaFromLibrary.toJson(true), edgeSchema));
}
Also used : Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 72 with StoreProperties

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

the class AbstractGraphLibraryTest method shouldNotOverwriteStorePropertiesWithClashingName.

@Test
public void shouldNotOverwriteStorePropertiesWithClashingName() throws Exception {
    final String clashingId = "clashingId";
    StoreProperties propsA = new StoreProperties();
    propsA.set("a", "a");
    StoreProperties propsB = new StoreProperties();
    propsB.set("b", "b");
    graphLibrary.addProperties(clashingId, propsA);
    assertThatExceptionOfType(OverwritingException.class).isThrownBy(() -> graphLibrary.add("graph", TEST_SCHEMA_ID, new Schema(), clashingId, propsB)).withMessageContaining("propertiesId clashingId already exists with a different store properties");
    StoreProperties storePropertiesFromLibrary = graphLibrary.getProperties(clashingId);
    assertEquals(propsA.getProperties(), storePropertiesFromLibrary.getProperties());
    assertNotEquals(propsB.getProperties(), storePropertiesFromLibrary.getProperties());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 73 with StoreProperties

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

the class SparkContextUtil method createSparkSession.

public static SparkSession createSparkSession(final StoreProperties storeProperties) {
    SparkSession.Builder builder = SparkSession.builder().appName(storeProperties.get(SparkConstants.APP_NAME, SparkConstants.DEFAULT_APP_NAME));
    if (Boolean.parseBoolean(storeProperties.get(SparkConstants.USE_SPARK_DEFAULT_CONF, "false"))) {
        final Properties properties = new Properties();
        final String sparkDefaultConfPath = storeProperties.get(SparkConstants.SPARK_DEFAULT_CONF_PATH, SparkConstants.DEFAULT_SPARK_DEFAULT_CONF_PATH);
        try {
            properties.load(Files.newBufferedReader(Paths.get(sparkDefaultConfPath)));
        } catch (final IOException e) {
            throw new IllegalArgumentException("Failed to read spark-default conf from " + sparkDefaultConfPath, e);
        }
        for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
            builder.config((String) entry.getKey(), (String) entry.getValue());
        }
        final String sparkMaster = storeProperties.get(SparkConstants.MASTER);
        builder = (sparkMaster == null || sparkMaster.isEmpty()) ? builder : builder.master(sparkMaster);
    } else {
        builder.master(storeProperties.get(SparkConstants.MASTER, SparkConstants.MASTER_DEFAULT));
    }
    builder.config(SparkConstants.SERIALIZER, storeProperties.get(SparkConstants.SERIALIZER, SparkConstants.DEFAULT_SERIALIZER)).config(SparkConstants.KRYO_REGISTRATOR, storeProperties.get(SparkConstants.KRYO_REGISTRATOR, SparkConstants.DEFAULT_KRYO_REGISTRATOR));
    return builder.getOrCreate();
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) IOException(java.io.IOException) Properties(java.util.Properties) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Map(java.util.Map)

Example 74 with StoreProperties

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

the class GraphDelegate method createGraphSerialisable.

public GraphSerialisable createGraphSerialisable(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final GraphHook[] hooks) {
    final GraphLibrary graphLibrary = store.getGraphLibrary();
    final Pair<Schema, StoreProperties> existingGraphPair = null != graphLibrary ? graphLibrary.get(graphId) : null;
    validateGraph(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair);
    final Schema resolvedSchema = resolveSchemaForGraph(store, schema, parentSchemaIds, existingGraphPair);
    final StoreProperties resolvedStoreProperties = resolveStorePropertiesForGraph(store, storeProperties, parentStorePropertiesId, existingGraphPair);
    return new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId(graphId).library(graphLibrary).addHooks(hooks).build()).schema(resolvedSchema).properties(resolvedStoreProperties).build();
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 75 with StoreProperties

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

the class GraphDelegate method resolveStorePropertiesForGraph.

protected StoreProperties resolveStorePropertiesForGraph(final Store store, final StoreProperties properties, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) {
    StoreProperties resultProps;
    if (null != existingGraphPair) {
        // If there is an existing graph then ignore any user provided properties and just use the existing properties
        resultProps = existingGraphPair.getSecond();
    } else {
        final GraphLibrary graphLibrary = store.getGraphLibrary();
        resultProps = (null == graphLibrary) ? properties : graphLibrary.resolveStoreProperties(properties, parentStorePropertiesId);
    }
    return resultProps;
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Aggregations

StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)170 Test (org.junit.jupiter.api.Test)136 Schema (uk.gov.gchq.gaffer.store.schema.Schema)102 Store (uk.gov.gchq.gaffer.store.Store)74 Context (uk.gov.gchq.gaffer.store.Context)47 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)42 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)39 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)26 Graph (uk.gov.gchq.gaffer.graph.Graph)26 Operation (uk.gov.gchq.gaffer.operation.Operation)24 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)20 User (uk.gov.gchq.gaffer.user.User)18 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)17 BeforeEach (org.junit.jupiter.api.BeforeEach)16 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)16 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)16 ExportToOtherGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph)14 HashSet (java.util.HashSet)13 FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)13