Search in sources :

Example 31 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.

the class DefaultSchemaRegistry method getSchemaBranch.

private SchemaBranch getSchemaBranch(Long id) throws SchemaBranchNotFoundException {
    List<QueryParam> schemaBranchQueryParam = new ArrayList<>();
    schemaBranchQueryParam.add(new QueryParam(SchemaBranchStorable.ID, id.toString()));
    Collection<SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, schemaBranchQueryParam);
    if (schemaBranchStorables == null || schemaBranchStorables.isEmpty())
        throw new SchemaBranchNotFoundException(String.format("Schema branch with id : '%s' not found", id.toString()));
    // size of the collection will always be less than 2, as ID is a primary key, so no need handle the case where size > 1
    return schemaBranchStorables.iterator().next().toSchemaBranch();
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) ArrayList(java.util.ArrayList)

Example 32 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.

the class DefaultSchemaRegistry method getSchemaKey.

private SchemaVersionKey getSchemaKey(Long schemaId) {
    SchemaVersionKey schemaVersionKey = null;
    List<QueryParam> queryParams = Collections.singletonList(new QueryParam(SchemaVersionStorable.ID, schemaId.toString()));
    Collection<SchemaVersionStorable> versionedSchemas = storageManager.find(SchemaVersionStorable.NAME_SPACE, queryParams);
    if (versionedSchemas != null && !versionedSchemas.isEmpty()) {
        SchemaVersionStorable storable = versionedSchemas.iterator().next();
        schemaVersionKey = new SchemaVersionKey(storable.getName(), storable.getVersion());
    }
    return schemaVersionKey;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam)

Example 33 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.

the class DefaultSchemaRegistry method getSchemaBranch.

private SchemaBranch getSchemaBranch(SchemaBranchKey schemaBranchKey) throws SchemaBranchNotFoundException {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(SchemaBranchStorable.NAME, schemaBranchKey.getSchemaBranchName()));
    queryParams.add(new QueryParam(SchemaBranchStorable.SCHEMA_METADATA_NAME, schemaBranchKey.getSchemaMetadataName()));
    Collection<SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, queryParams);
    if (schemaBranchStorables == null || schemaBranchStorables.isEmpty())
        throw new SchemaBranchNotFoundException(String.format("Schema branch with key : %s not found", schemaBranchKey));
    else if (schemaBranchStorables.size() > 1)
        throw new SchemaBranchNotFoundException(String.format("Failed to unique determine a schema branch with key : %s", schemaBranchKey));
    return schemaBranchStorables.iterator().next().toSchemaBranch();
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) ArrayList(java.util.ArrayList)

Example 34 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.

the class StorableTest method buildQueryParamsForPrimaryKey.

protected List<QueryParam> buildQueryParamsForPrimaryKey(Storable storable) {
    final Map<Schema.Field, Object> fieldsToVal = storable.getPrimaryKey().getFieldsToVal();
    final List<QueryParam> queryParams = new ArrayList<>(fieldsToVal.size());
    for (Schema.Field field : fieldsToVal.keySet()) {
        QueryParam qp = new QueryParam(field.getName(), fieldsToVal.get(field).toString());
        queryParams.add(qp);
    }
    return queryParams;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) Schema(com.hortonworks.registries.common.Schema) ArrayList(java.util.ArrayList)

Example 35 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.

the class AbstractStoreManagerTest method testFind_NonExistentQueryParams_EmptyList.

@Test
public void testFind_NonExistentQueryParams_EmptyList() {
    for (StorableTest test : storableTests) {
        test.addAllToStorage();
        List<QueryParam> queryParams = new ArrayList<QueryParam>() {

            {
                add(new QueryParam("NON_EXISTING_FIELD_1", "NON_EXISTING_VAL_1"));
                add(new QueryParam("NON_EXISTING_FIELD_2", "NON_EXISTING_VAL_2"));
            }
        };
        final Collection<Storable> allMatchingQueryParamsFilter = getStorageManager().find(test.getNameSpace(), queryParams);
        assertIterators(Collections.EMPTY_LIST, allMatchingQueryParamsFilter);
    }
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)72 ArrayList (java.util.ArrayList)42 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)22 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)22 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)22 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)22 IOException (java.io.IOException)8 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)7 StorableKey (com.hortonworks.registries.storage.StorableKey)7 OrderByField (com.hortonworks.registries.storage.OrderByField)6 HashSet (java.util.HashSet)6 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)5 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)5 Timed (com.codahale.metrics.annotation.Timed)4 Preconditions (com.google.common.base.Preconditions)4 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)4 StorageException (com.hortonworks.registries.storage.exception.StorageException)4 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4