Java Code Examples for com.thinkaurelius.titan.core.schema.TitanIndex

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.schema.TitanIndex. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 6 votes vote down vote up
public Consumer<ScanMetrics> getIndexJobFinisher(final TitanGraph graph, final SchemaAction action) {
    Preconditions.checkArgument((graph != null && action != null) || (graph == null && action == null));
    return metrics -> {
        try {
            if (metrics.get(ScanMetrics.Metric.FAILURE) == 0) {
                if (action != null) {
                    ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
                    try {
                        TitanIndex index = retrieve(mgmt);
                        mgmt.updateIndex(index, action);
                    } finally {
                        mgmt.commit();
                    }
                }
                LOGGER.info("Index update job successful for [{}]", IndexIdentifier.this.toString());
            } else {
                LOGGER.error("Index update job unsuccessful for [{}]. Check logs", IndexIdentifier.this.toString());
            }
        } catch (Throwable e) {
            LOGGER.error("Error encountered when updating index after job finished [" + IndexIdentifier.this.toString() + "]: ", e);
        }
    };
}
 
Example 2
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 6 votes vote down vote up
public Consumer<ScanMetrics> getIndexJobFinisher(final TitanGraph graph, final SchemaAction action) {
    Preconditions.checkArgument((graph != null && action != null) || (graph == null && action == null));
    return metrics -> {
        try {
            if (metrics.get(ScanMetrics.Metric.FAILURE) == 0) {
                if (action != null) {
                    ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
                    try {
                        TitanIndex index = retrieve(mgmt);
                        mgmt.updateIndex(index, action);
                    } finally {
                        mgmt.commit();
                    }
                }
                LOGGER.info("Index update job successful for [{}]", IndexIdentifier.this.toString());
            } else {
                LOGGER.error("Index update job unsuccessful for [{}]. Check logs", IndexIdentifier.this.toString());
            }
        } catch (Throwable e) {
            LOGGER.error("Error encountered when updating index after job finished [" + IndexIdentifier.this.toString() + "]: ", e);
        }
    };
}
 
Example 3
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
private IndexIdentifier(TitanIndex index) {
    Preconditions.checkArgument(index != null);
    indexName = index.name();
    if (index instanceof RelationTypeIndex) relationTypeName = ((RelationTypeIndex) index).getType().name();
    else relationTypeName = null;
    Preconditions.checkArgument(StringUtils.isNotBlank(indexName));
    hashcode = new HashCodeBuilder().append(indexName).append(relationTypeName).hashCode();
}
 
Example 4
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
private IndexIdentifier(TitanIndex index) {
    Preconditions.checkArgument(index != null);
    indexName = index.name();
    if (index instanceof RelationTypeIndex) relationTypeName = ((RelationTypeIndex) index).getType().name();
    else relationTypeName = null;
    Preconditions.checkArgument(StringUtils.isNotBlank(indexName));
    hashcode = new HashCodeBuilder().append(indexName).append(relationTypeName).hashCode();
}
 
Example 5
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 4 votes vote down vote up
@Override
public IndexJobFuture getIndexJobStatus(TitanIndex index) {
    IndexIdentifier indexId = new IndexIdentifier(index);
    return graph.getBackend().getScanJobStatus(indexId);
}
 
Example 6
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 4 votes vote down vote up
private TitanIndex retrieve(ManagementSystem mgmt) {
    if (relationTypeName == null) return mgmt.getGraphIndex(indexName);
    else return mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), indexName);
}
 
Example 7
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 4 votes vote down vote up
@Override
public IndexJobFuture getIndexJobStatus(TitanIndex index) {
    IndexIdentifier indexId = new IndexIdentifier(index);
    return graph.getBackend().getScanJobStatus(indexId);
}
 
Example 8
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 4 votes vote down vote up
private TitanIndex retrieve(ManagementSystem mgmt) {
    if (relationTypeName == null) return mgmt.getGraphIndex(indexName);
    else return mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), indexName);
}
 
Example 9
Project: titan0.5.4-hbase1.1.1-custom   File: ManagementSystem.java   View source code 4 votes vote down vote up
@Override
public void updateIndex(TitanIndex index, SchemaAction updateAction) {
    Preconditions.checkArgument(updateAction!=null,"Need to provide update action");
    Preconditions.checkArgument(updateAction!=SchemaAction.REMOVE_INDEX);

    TitanSchemaVertex schemaVertex = getSchemaVertex(index);
    Set<TitanSchemaVertex> dependentTypes;
    Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
    if (index instanceof RelationTypeIndex) {
        dependentTypes = ImmutableSet.of((TitanSchemaVertex)((InternalRelationType)schemaVertex).getBaseType());
        Preconditions.checkArgument(updateAction.getApplicableStatus().contains(schemaVertex.getStatus()),
                "Update action [%s] does not apply for index with status [%s]",updateAction,schemaVertex.getStatus());
    } else if (index instanceof TitanGraphIndex) {
        IndexType indexType = schemaVertex.asIndexType();
        dependentTypes = Sets.newHashSet();
        if (indexType.isCompositeIndex()) {
            Preconditions.checkArgument(updateAction.getApplicableStatus().contains(schemaVertex.getStatus()),
                    "Update action [%s] does not apply for index with status [%s]",updateAction,schemaVertex.getStatus());
            for (PropertyKey key : ((TitanGraphIndex)index).getFieldKeys()) {
                dependentTypes.add((PropertyKeyVertex)key);
            }
        } else {
            keySubset = Sets.newHashSet();
            MixedIndexType cindexType = (MixedIndexType)indexType;
            Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
            for (ParameterIndexField field : cindexType.getFieldKeys()) {
                if (applicableStatus.contains(field.getStatus())) keySubset.add((PropertyKeyVertex)field.getFieldKey());
            }
            Preconditions.checkArgument(!keySubset.isEmpty(),"Update action [%s] does not apply to any fields for index [%s]",updateAction,index);
            dependentTypes.addAll(keySubset);
        }
    } else throw new UnsupportedOperationException("Updates not supported for index: " + index);

    switch(updateAction) {
        case REGISTER_INDEX:
            setStatus(schemaVertex,SchemaStatus.INSTALLED,keySubset);
            updatedTypes.add(schemaVertex);
            updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
            break;
        case REINDEX:
            throw new UnsupportedOperationException(updateAction + " requires a manual step: run a MapReduce reindex on index name \"" + index.getName() + "\"");
        case ENABLE_INDEX:
            setStatus(schemaVertex,SchemaStatus.ENABLED,keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty()) updatedTypes.addAll(dependentTypes);
            break;
        case DISABLE_INDEX:
            setStatus(schemaVertex,SchemaStatus.INSTALLED,keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty()) updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
            break;
        case REMOVE_INDEX:
            throw new UnsupportedOperationException("Removing indexes is not yet supported");
        default: throw new UnsupportedOperationException("Update action not supported: " + updateAction);
    }
}