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));
}
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());
}
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();
}
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();
}
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;
}
Aggregations