use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class MongoDetailsAdapter method toRyaDetails.
/**
* Converts a MongoDB {@link DBObject} into its {@link RyaDetails} equivalent.
*
* @param mongoObj - The MongoDB object to convert. (not null)
* @return The equivalent {@link RyaDetails} object.
* @throws MalformedRyaDetailsException The MongoDB object could not be converted.
*/
public static RyaDetails toRyaDetails(final DBObject mongoObj) throws MalformedRyaDetailsException {
requireNonNull(mongoObj);
final BasicDBObject basicObj = (BasicDBObject) mongoObj;
try {
final RyaDetails.Builder builder = RyaDetails.builder().setRyaInstanceName(basicObj.getString(INSTANCE_KEY)).setRyaVersion(basicObj.getString(VERSION_KEY)).setEntityCentricIndexDetails(new EntityCentricIndexDetails(basicObj.getBoolean(ENTITY_DETAILS_KEY))).setPCJIndexDetails(getPCJIndexDetails(basicObj)).setTemporalIndexDetails(new TemporalIndexDetails(basicObj.getBoolean(TEMPORAL_DETAILS_KEY))).setFreeTextDetails(new FreeTextIndexDetails(basicObj.getBoolean(FREETEXT_DETAILS_KEY))).setProspectorDetails(new ProspectorDetails(Optional.<Date>fromNullable(basicObj.getDate(PROSPECTOR_DETAILS_KEY)))).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.<Date>fromNullable(basicObj.getDate(JOIN_SELECTIVITY_DETAILS_KEY))));
// If the Rya Streams Details are present, then add them.
if (basicObj.containsField(RYA_STREAMS_DETAILS_KEY)) {
final BasicDBObject streamsObject = (BasicDBObject) basicObj.get(RYA_STREAMS_DETAILS_KEY);
final String hostname = streamsObject.getString(RYA_STREAMS_HOSTNAME_KEY);
final int port = streamsObject.getInt(RYA_STREAMS_PORT_KEY);
builder.setRyaStreamsDetails(new RyaStreamsDetails(hostname, port));
}
return builder.build();
} catch (final Exception e) {
throw new MalformedRyaDetailsException("Failed to make RyaDetail from Mongo Object, it is malformed.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class MongoDetailsAdapter method toDBObject.
/**
* Converts a {@link RyaDetails} object into its MongoDB {@link DBObject} equivalent.
*
* @param details - The details to convert. (not null)
* @return The MongoDB {@link DBObject} equivalent.
*/
public static BasicDBObject toDBObject(final RyaDetails details) {
requireNonNull(details);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().add(INSTANCE_KEY, details.getRyaInstanceName()).add(VERSION_KEY, details.getRyaVersion()).add(ENTITY_DETAILS_KEY, details.getEntityCentricIndexDetails().isEnabled()).add(PCJ_DETAILS_KEY, toDBObject(details.getPCJIndexDetails())).add(TEMPORAL_DETAILS_KEY, details.getTemporalIndexDetails().isEnabled()).add(FREETEXT_DETAILS_KEY, details.getFreeTextIndexDetails().isEnabled());
if (details.getProspectorDetails().getLastUpdated().isPresent()) {
builder.add(PROSPECTOR_DETAILS_KEY, details.getProspectorDetails().getLastUpdated().get());
}
if (details.getJoinSelectivityDetails().getLastUpdated().isPresent()) {
builder.add(JOIN_SELECTIVITY_DETAILS_KEY, details.getJoinSelectivityDetails().getLastUpdated().get());
}
// If the Rya Streams Details are present, then add them.
if (details.getRyaStreamsDetails().isPresent()) {
final RyaStreamsDetails ryaStreamsDetails = details.getRyaStreamsDetails().get();
// The embedded object that holds onto the fields.
final DBObject ryaStreamsFields = BasicDBObjectBuilder.start().add(RYA_STREAMS_HOSTNAME_KEY, ryaStreamsDetails.getHostname()).add(RYA_STREAMS_PORT_KEY, ryaStreamsDetails.getPort()).get();
// Add them to the main builder.
builder.add(RYA_STREAMS_DETAILS_KEY, ryaStreamsFields);
}
return (BasicDBObject) builder.get();
}
use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class AccumuloSetRyaStreamsConfigurationIT method updatesRyaDetails.
@Test
public void updatesRyaDetails() throws Exception {
final String ryaInstance = getRyaInstanceName();
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
// Install an instance of Rya.
final Install installRya = ryaClient.getInstall();
final InstallConfiguration installConf = InstallConfiguration.builder().build();
installRya.install(ryaInstance, installConf);
// Fetch its details and show they do not have any RyaStreamsDetails.
com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
assertFalse(streamsDetails.isPresent());
// Set the details.
final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
// Fetch its details again and show that they are now filled in.
streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
assertEquals(details, streamsDetails.get());
}
use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class AccumuloSetRyaStreamsConfigurationIT method instanceDoesNotExist.
@Test(expected = InstanceDoesNotExistException.class)
public void instanceDoesNotExist() throws Exception {
final String ryaInstance = getRyaInstanceName();
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
// Skip the install step to create error causing situation.
final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
}
use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class RyaDetailsTest method constructor.
@Test
public void constructor() {
final RyaDetails originalDetails = RyaDetails.builder().setRyaInstanceName("test_instance").setRyaVersion("1.2.3.4").setEntityCentricIndexDetails(new EntityCentricIndexDetails(true)).setTemporalIndexDetails(new TemporalIndexDetails(true)).setFreeTextDetails(new FreeTextIndexDetails(true)).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true).setFluoDetails(new FluoDetails("test_instance_rya_pcj_updater")).addPCJDetails(PCJDetails.builder().setId("pcj 1").setUpdateStrategy(PCJUpdateStrategy.BATCH).setLastUpdateTime(new Date())).addPCJDetails(PCJDetails.builder().setId("pcj 2").setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL))).setProspectorDetails(new ProspectorDetails(Optional.of(new Date()))).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.of(new Date()))).setRyaStreamsDetails(new RyaStreamsDetails("localhost", 5)).build();
// Create a new Builder using another RyaDetails object.
final RyaDetails.Builder builder = new RyaDetails.Builder(originalDetails);
// Show it builds the object that was passed into it.
assertEquals(originalDetails, builder.build());
}
Aggregations