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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations