Search in sources :

Example 1 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class DocTableInfoBuilder method docIndexMetaData.

private DocIndexMetaData docIndexMetaData() {
    DocIndexMetaData docIndexMetaData;
    String templateName = PartitionName.templateName(ident.schema(), ident.name());
    boolean createdFromTemplate = false;
    if (metaData.getTemplates().containsKey(templateName)) {
        docIndexMetaData = buildDocIndexMetaDataFromTemplate(ident.indexName(), templateName);
        createdFromTemplate = true;
        concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), ident.indexName());
    } else {
        try {
            concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), ident.indexName());
            if (concreteIndices.length == 0) {
                // no matching index found
                throw new TableUnknownException(ident);
            }
            docIndexMetaData = buildDocIndexMetaData(concreteIndices[0]);
        } catch (IndexNotFoundException ex) {
            throw new TableUnknownException(ident.fqn(), ex);
        }
    }
    if ((!createdFromTemplate && concreteIndices.length == 1) || !checkAliasSchema) {
        return docIndexMetaData;
    }
    for (String concreteIndice : concreteIndices) {
        if (IndexMetaData.State.CLOSE.equals(metaData.indices().get(concreteIndice).getState())) {
            throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to access the partition %s, it is closed", concreteIndice));
        }
        try {
            docIndexMetaData = docIndexMetaData.merge(buildDocIndexMetaData(concreteIndice), transportPutIndexTemplateAction, createdFromTemplate);
        } catch (IOException e) {
            throw new UnhandledServerException("Unable to merge/build new DocIndexMetaData", e);
        }
    }
    return docIndexMetaData;
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) TableUnknownException(io.crate.exceptions.TableUnknownException) IOException(java.io.IOException)

Example 2 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class DocTableInfoBuilder method buildDocIndexMetaDataFromTemplate.

private DocIndexMetaData buildDocIndexMetaDataFromTemplate(String index, String templateName) {
    IndexTemplateMetaData indexTemplateMetaData = metaData.getTemplates().get(templateName);
    DocIndexMetaData docIndexMetaData;
    try {
        IndexMetaData.Builder builder = new IndexMetaData.Builder(index);
        builder.putMapping(Constants.DEFAULT_MAPPING_TYPE, indexTemplateMetaData.getMappings().get(Constants.DEFAULT_MAPPING_TYPE).toString());
        Settings.Builder settingsBuilder = Settings.builder().put(indexTemplateMetaData.settings()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
        Settings settings = settingsBuilder.build();
        builder.settings(settings);
        builder.numberOfShards(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
        builder.numberOfReplicas(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
        docIndexMetaData = new DocIndexMetaData(functions, builder.build(), ident);
    } catch (IOException e) {
        throw new UnhandledServerException("Unable to build DocIndexMetaData from template", e);
    }
    return docIndexMetaData.build();
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) UnhandledServerException(io.crate.exceptions.UnhandledServerException) IOException(java.io.IOException) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 3 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class LuceneReferenceResolver method getImplementation.

@Override
public LuceneCollectorExpression<?> getImplementation(Reference refInfo) {
    assert refInfo.granularity() == RowGranularity.DOC : "lucene collector expressions are required to be on DOC granularity";
    ColumnIdent columnIdent = refInfo.ident().columnIdent();
    String name = columnIdent.name();
    if (RawCollectorExpression.COLUMN_NAME.equals(name)) {
        if (columnIdent.isColumn()) {
            return new RawCollectorExpression();
        } else {
            // TODO: implement an Object source expression which may support subscripts
            throw new UnsupportedFeatureException(String.format(Locale.ENGLISH, "_source expression does not support subscripts %s", columnIdent.fqn()));
        }
    } else if (UidCollectorExpression.COLUMN_NAME.equals(name)) {
        return new UidCollectorExpression();
    } else if (IdCollectorExpression.COLUMN_NAME.equals(name)) {
        return new IdCollectorExpression();
    } else if (DocCollectorExpression.COLUMN_NAME.equals(name)) {
        return DocCollectorExpression.create(refInfo);
    } else if (FetchIdCollectorExpression.COLUMN_NAME.equals(name)) {
        return new FetchIdCollectorExpression();
    } else if (ScoreCollectorExpression.COLUMN_NAME.equals(name)) {
        return new ScoreCollectorExpression();
    }
    String colName = columnIdent.fqn();
    MappedFieldType fieldType = fieldTypeLookup.get(colName);
    if (fieldType == null) {
        return new NullValueCollectorExpression(colName);
    }
    switch(refInfo.valueType().id()) {
        case ByteType.ID:
            return new ByteColumnReference(colName);
        case ShortType.ID:
            return new ShortColumnReference(colName);
        case IpType.ID:
            return new IpColumnReference(colName);
        case StringType.ID:
            return new BytesRefColumnReference(colName, fieldType);
        case DoubleType.ID:
            return new DoubleColumnReference(colName, fieldType);
        case BooleanType.ID:
            return new BooleanColumnReference(colName);
        case ObjectType.ID:
            return new ObjectColumnReference(colName);
        case FloatType.ID:
            return new FloatColumnReference(colName, fieldType);
        case LongType.ID:
        case TimestampType.ID:
            return new LongColumnReference(colName);
        case IntegerType.ID:
            return new IntegerColumnReference(colName);
        case GeoPointType.ID:
            return new GeoPointColumnReference(colName, fieldType);
        case GeoShapeType.ID:
            return new GeoShapeColumnReference(colName);
        case ArrayType.ID:
        case SetType.ID:
            return DocCollectorExpression.create(DocReferenceConverter.toSourceLookup(refInfo));
        default:
            throw new UnhandledServerException(String.format(Locale.ENGLISH, "unsupported type '%s'", refInfo.valueType().getName()));
    }
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) ColumnIdent(io.crate.metadata.ColumnIdent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) UnhandledServerException(io.crate.exceptions.UnhandledServerException)

Example 4 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class AccessControlMaySeeTest method testUnscopedException.

@Test
public void testUnscopedException() throws Exception {
    accessControl.ensureMaySee(new UnhandledServerException("unhandled"));
    assertThat(validationCallArguments.size(), is(0));
}
Also used : UnhandledServerException(io.crate.exceptions.UnhandledServerException) Test(org.junit.Test)

Example 5 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class DocTableInfoBuilder method buildDocIndexMetadataFromTemplate.

private DocIndexMetadata buildDocIndexMetadataFromTemplate(String index, String templateName) {
    IndexTemplateMetadata indexTemplateMetadata = metadata.getTemplates().get(templateName);
    DocIndexMetadata docIndexMetadata;
    try {
        IndexMetadata.Builder builder = new IndexMetadata.Builder(index);
        builder.putMapping(Constants.DEFAULT_MAPPING_TYPE, indexTemplateMetadata.getMappings().get(Constants.DEFAULT_MAPPING_TYPE).toString());
        Settings.Builder settingsBuilder = Settings.builder().put(indexTemplateMetadata.settings()).put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT);
        Settings settings = settingsBuilder.build();
        builder.settings(settings);
        builder.numberOfShards(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
        builder.numberOfReplicas(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
        docIndexMetadata = new DocIndexMetadata(nodeCtx, builder.build(), ident);
    } catch (IOException e) {
        throw new UnhandledServerException("Unable to build DocIndexMetadata from template", e);
    }
    return docIndexMetadata.build();
}
Also used : IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) UnhandledServerException(io.crate.exceptions.UnhandledServerException) IOException(java.io.IOException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

UnhandledServerException (io.crate.exceptions.UnhandledServerException)13 IOException (java.io.IOException)4 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)3 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Settings (org.elasticsearch.common.settings.Settings)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 Test (org.junit.Test)2 SharedShardContext (io.crate.action.job.SharedShardContext)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 OrderBy (io.crate.analyze.OrderBy)1