Search in sources :

Example 16 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphBackup method propertyToJson.

private JSONObject propertyToJson(Property property) {
    JSONObject json = new JSONObject();
    json.put("key", property.getKey());
    json.put("name", property.getName());
    json.put("visibility", property.getVisibility().getVisibilityString());
    Object value = property.getValue();
    if (!(value instanceof StreamingPropertyValue)) {
        json.put("value", objectToJsonString(value));
    }
    Metadata metadata = property.getMetadata();
    if (metadata != null) {
        json.put("metadata", metadataToJson(metadata));
    }
    return json;
}
Also used : JSONObject(org.json.JSONObject) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) JSONObject(org.json.JSONObject)

Example 17 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphBackup method saveStreamingProperty.

private void saveStreamingProperty(OutputStream out, Property property) throws IOException {
    StreamingPropertyValue spv = (StreamingPropertyValue) property.getValue();
    JSONObject json = propertyToJson(property);
    json.put("valueType", spv.getValueType().getName());
    json.put("searchIndex", spv.isSearchIndex());
    json.put("store", spv.isStore());
    out.write('D');
    out.write(json.toString().getBytes());
    out.write('\n');
    InputStream in = spv.getInputStream();
    byte[] buffer = new byte[10 * 1024];
    int read;
    while ((read = in.read(buffer)) > 0) {
        out.write(Integer.toString(read).getBytes());
        out.write('\n');
        out.write(buffer, 0, read);
        out.write('\n');
    }
    out.write('0');
    out.write('\n');
}
Also used : JSONObject(org.json.JSONObject) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue)

Example 18 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphRestore method restoreStreamingPropertyValue.

private void restoreStreamingPropertyValue(InputStream in, Graph graph, JSONObject propertyJson, Element element, Authorizations authorizations) throws ClassNotFoundException, IOException {
    String key = propertyJson.getString("key");
    String name = propertyJson.getString("name");
    Metadata metadata = jsonToPropertyMetadata(propertyJson.optJSONObject("metadata"));
    Visibility visibility = new Visibility(propertyJson.getString("visibility"));
    Class valueType = Class.forName(propertyJson.getString("valueType"));
    InputStream spvin = new StreamingPropertyValueInputStream(in);
    StreamingPropertyValue value = StreamingPropertyValue.create(spvin, valueType);
    value.searchIndex(propertyJson.optBoolean("searchIndex", false));
    value.store(propertyJson.optBoolean("store", true));
    element.addPropertyValue(key, name, value, metadata, visibility, authorizations);
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue)

Example 19 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class AccumuloGraphTestBase method addLegacySPVData.

// need to add it manually because the key format changed
private void addLegacySPVData(String vertexId, long timestamp, String propertyKey, String propertyName, String propertyValue) throws MutationsRejectedException {
    String dataRowKey = new DataTableRowKey(vertexId, propertyKey, propertyName).getRowKey() + VALUE_SEPARATOR + timestamp;
    Mutation addPropertyMutation = new Mutation(vertexId);
    byte[] data = propertyValue.getBytes();
    StreamingPropertyValue spv = StreamingPropertyValue.create(propertyValue);
    StreamingPropertyValueTableRef spvValue = new StreamingPropertyValueTableRef(dataRowKey, spv, data);
    Metadata metadata = new Metadata();
    Property property = new MutablePropertyImpl(propertyKey, propertyName, spvValue, metadata, timestamp, new HashSet<>(), new Visibility(""), FetchHints.ALL);
    Text columnQualifier = KeyHelper.getColumnQualifierFromPropertyColumnQualifier(property, getGraph().getNameSubstitutionStrategy());
    addPropertyMutation.put(AccumuloElement.CF_PROPERTY, columnQualifier, new Value(getGraph().getVertexiumSerializer().objectToBytes(spvValue)));
    getGraph().getVerticesWriter().addMutation(addPropertyMutation);
    Mutation addDataMutation = new Mutation(dataRowKey);
    addDataMutation.put(EMPTY_TEXT, EMPTY_TEXT, timestamp - 1000, new Value(data));
    getGraph().getDataWriter().addMutation(addDataMutation);
    getGraph().flush();
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Text(org.apache.hadoop.io.Text) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) MutablePropertyImpl(org.vertexium.property.MutablePropertyImpl) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Mutation(org.apache.accumulo.core.data.Mutation)

Example 20 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class AccumuloGraphTestBase method testDeleteHistoricalLegacyStreamingPropertyValueData_keysWithCommonPrefix.

@Test
public void testDeleteHistoricalLegacyStreamingPropertyValueData_keysWithCommonPrefix() throws Exception {
    String vertexId = "v1";
    graph.prepareVertex(vertexId, VISIBILITY_EMPTY).save(AUTHORIZATIONS_EMPTY);
    graph.flush();
    long timestamp = new Date().getTime();
    String propertyKey1 = "prefix";
    String propertyKey2 = "prefixSuffix";
    String propertyName = "prop1";
    String propertyValue = "Hello";
    addLegacySPVData(vertexId, timestamp, propertyKey1, propertyName, propertyValue);
    addLegacySPVData(vertexId, timestamp, propertyKey2, propertyName, propertyValue);
    getGraph().flush();
    new DeleteHistoricalLegacyStreamingPropertyValueData(getGraph()).execute(new DeleteHistoricalLegacyStreamingPropertyValueData.Options().setDryRun(false).setVersionsToKeep(1), AUTHORIZATIONS_EMPTY);
    // verify we can still retrieve it
    Vertex v1 = graph.getVertex(vertexId, AUTHORIZATIONS_EMPTY);
    StreamingPropertyValue spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey1, propertyName);
    assertNotNull("spv should not be null", spv);
    assertEquals(propertyValue, IOUtils.toString(spv.getInputStream()));
    spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey2, propertyName);
    assertNotNull("spv should not be null", spv);
    assertEquals(propertyValue, IOUtils.toString(spv.getInputStream()));
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) DeleteHistoricalLegacyStreamingPropertyValueData(org.vertexium.accumulo.tools.DeleteHistoricalLegacyStreamingPropertyValueData) Test(org.junit.Test)

Aggregations

StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)22 LargeStringInputStream (org.vertexium.test.util.LargeStringInputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)6 PropertyValue (org.vertexium.property.PropertyValue)6 Test (org.junit.Test)4 IndexHint (org.vertexium.search.IndexHint)4 Mutation (org.apache.accumulo.core.data.Mutation)3 Value (org.apache.accumulo.core.data.Value)3 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)3 Text (org.apache.hadoop.io.Text)2 JSONObject (org.json.JSONObject)2 DeleteHistoricalLegacyStreamingPropertyValueData (org.vertexium.accumulo.tools.DeleteHistoricalLegacyStreamingPropertyValueData)2 VertexiumException (org.vertexium.VertexiumException)1 StreamingPropertyValueTableDataRef (org.vertexium.accumulo.StreamingPropertyValueTableDataRef)1 InMemoryGraph (org.vertexium.inmemory.InMemoryGraph)1 AlterPropertyVisibility (org.vertexium.mutation.AlterPropertyVisibility)1 ExtendedDataMutation (org.vertexium.mutation.ExtendedDataMutation)1 SetPropertyMetadata (org.vertexium.mutation.SetPropertyMetadata)1 MutablePropertyImpl (org.vertexium.property.MutablePropertyImpl)1