Search in sources :

Example 21 with QueryParam

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

the class ComponentCatalogResource method buildServiceIdAwareQueryParams.

private List<QueryParam> buildServiceIdAwareQueryParams(Long serviceId, UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam("serviceId", serviceId.toString()));
    if (uriInfo != null) {
        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
        if (!params.isEmpty()) {
            queryParams.addAll(WSUtils.buildQueryParameters(params));
        }
    }
    return queryParams;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList)

Example 22 with QueryParam

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

the class EnvironmentServiceTest method invalidateContainersWhenImportingClusterServices.

@Test
public void invalidateContainersWhenImportingClusterServices() throws Exception {
    Deencapsulation.setField(environmentService, "clusterImporter", clusterImporter);
    long clusterId = 1L;
    Cluster testCluster = new Cluster();
    testCluster.setId(clusterId);
    ArrayList<Long> namespaceIds = Lists.newArrayList(1L, 2L, 3L);
    List<NamespaceServiceClusterMap> mappings = new ArrayList<>();
    mappings.add(new NamespaceServiceClusterMap(1L, "STORM", clusterId));
    mappings.add(new NamespaceServiceClusterMap(2L, "KAFKA", clusterId));
    mappings.add(new NamespaceServiceClusterMap(3L, "HADOOP", clusterId));
    MockedNamespaceAwareContainer container1 = new MockedNamespaceAwareContainer();
    MockedNamespaceAwareContainer container2 = new MockedNamespaceAwareContainer();
    environmentService.addNamespaceAwareContainer(container1);
    environmentService.addNamespaceAwareContainer(container2);
    new Expectations() {

        {
            clusterImporter.importCluster(discoverer, testCluster);
            result = testCluster;
            dao.find(NAMESPACE_SERVICE_CLUSTER_MAP, Collections.singletonList(new QueryParam("clusterId", String.valueOf(clusterId))));
            result = mappings;
        }
    };
    // we're just checking whether it calls invalidation to associated containers properly
    environmentService.importClusterServices(discoverer, testCluster);
    assertEquals(3, container1.getInvalidatedNamespaceIds().size());
    assertTrue(container1.getInvalidatedNamespaceIds().containsAll(namespaceIds));
    assertEquals(3, container2.getInvalidatedNamespaceIds().size());
    assertTrue(container2.getInvalidatedNamespaceIds().containsAll(namespaceIds));
}
Also used : Expectations(mockit.Expectations) QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Test(org.junit.Test)

Example 23 with QueryParam

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

the class JdbcStorageManager method buildStorableKey.

// private helper methods
/**
 * Query parameters are typically specified for a column or key in a database table or storage namespace. Therefore, we build
 * the {@link StorableKey} from the list of query parameters, and then can use {@link SqlSelectQuery} builder to generate the query using
 * the query parameters in the where clause
 *
 * @return {@link StorableKey} with all query parameters that match database columns <br/>
 * null if none of the query parameters specified matches a column in the DB
 */
private StorableKey buildStorableKey(String namespace, List<QueryParam> queryParams) throws Exception {
    final Map<Schema.Field, Object> fieldsToVal = new HashMap<>();
    StorableKey storableKey = null;
    try {
        CaseAgnosticStringSet columnNames = queryExecutor.getColumnNames(namespace);
        for (QueryParam qp : queryParams) {
            if (!columnNames.contains(qp.getName())) {
                log.warn("Query parameter [{}] does not exist for namespace [{}]. Query parameter ignored.", qp.getName(), namespace);
            } else {
                final String val = qp.getValue();
                final Schema.Type typeOfVal = Schema.Type.getTypeOfVal(val);
                fieldsToVal.put(new Schema.Field(qp.getName(), typeOfVal), // instantiates object of the appropriate type
                typeOfVal.getJavaType().getConstructor(String.class).newInstance(val));
            }
        }
        // it is empty when none of the query parameters specified matches a column in the DB
        if (!fieldsToVal.isEmpty()) {
            final PrimaryKey primaryKey = new PrimaryKey(fieldsToVal);
            storableKey = new StorableKey(namespace, primaryKey);
        }
        log.debug("Building StorableKey from QueryParam: \n\tnamespace = [{}]\n\t queryParams = [{}]\n\t StorableKey = [{}]", namespace, queryParams, storableKey);
    } catch (Exception e) {
        log.debug("Exception occurred when attempting to generate StorableKey from QueryParam", e);
        throw new IllegalQueryParameterException(e);
    }
    return storableKey;
}
Also used : HashMap(java.util.HashMap) Schema(com.hortonworks.registries.common.Schema) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) StorageException(com.hortonworks.registries.storage.exception.StorageException) IllegalQueryParameterException(com.hortonworks.registries.storage.exception.IllegalQueryParameterException) OrderByField(com.hortonworks.registries.storage.OrderByField) CaseAgnosticStringSet(com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet) QueryParam(com.hortonworks.registries.common.QueryParam) StorableKey(com.hortonworks.registries.storage.StorableKey) IllegalQueryParameterException(com.hortonworks.registries.storage.exception.IllegalQueryParameterException)

Example 24 with QueryParam

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

the class InMemoryStorageManager method matches.

/**
 * Uses reflection to query the field or the method. Assumes
 * a public getXXX method is available to get the field value.
 */
private boolean matches(Storable val, List<QueryParam> queryParams, Class<?> clazz) {
    Object fieldValue;
    boolean res = true;
    for (QueryParam qp : queryParams) {
        try {
            fieldValue = ReflectionHelper.invokeGetter(qp.name, val);
            if (!fieldValue.toString().equals(qp.value)) {
                return false;
            }
        } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
            LOG.error("FAILED to invoke getter for query param {} , is your param name correct?", qp.getName(), e);
            return false;
        }
    }
    return res;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 25 with QueryParam

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

the class SchemaVersionLifecycleManager method createSchemaVersionLifeCycleContext.

public SchemaVersionLifecycleContext createSchemaVersionLifeCycleContext(Long schemaVersionId, SchemaVersionLifecycleState schemaVersionLifecycleState) throws SchemaNotFoundException {
    // get the current state from storage for the given versionID
    // we can use a query to get max value for the column for a given schema-version-id but StorageManager does not
    // have API to take custom queries.
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(SchemaVersionStateStorable.SCHEMA_VERSION_ID, schemaVersionId.toString()));
    queryParams.add(new QueryParam(SchemaVersionStateStorable.STATE, schemaVersionLifecycleState.getId().toString()));
    Collection<SchemaVersionStateStorable> schemaVersionStates = storageManager.find(SchemaVersionStateStorable.NAME_SPACE, queryParams, Collections.singletonList(OrderByField.of(SchemaVersionStateStorable.SEQUENCE, true)));
    if (schemaVersionStates.isEmpty()) {
        throw new SchemaNotFoundException("No schema versions found with id " + schemaVersionId);
    }
    SchemaVersionStateStorable stateStorable = schemaVersionStates.iterator().next();
    SchemaVersionService schemaVersionService = createSchemaVersionService();
    SchemaVersionLifecycleContext context = new SchemaVersionLifecycleContext(stateStorable.getSchemaVersionId(), stateStorable.getSequence(), schemaVersionService, schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
    context.setDetails(stateStorable.getDetails());
    return context;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) SchemaVersionService(com.hortonworks.registries.schemaregistry.state.SchemaVersionService) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

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