use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityDataServiceTest method testUpdateEntity.
@Test
public void testUpdateEntity() {
Entity entity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
Entity createdEntity = entityDataServiceClient.upsert(entity);
assertNotNull(createdEntity);
assertNotNull(createdEntity.getEntityId().trim());
Entity updatedEntity = Entity.newBuilder(createdEntity).setEntityName("Updated Service").build();
updatedEntity = entityDataServiceClient.upsert(updatedEntity);
assertEquals("Updated Service", updatedEntity.getEntityName());
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceTest method testExecuteWithEqualsArrayFilter.
@Test
@Disabled("Disabled until we enable querying based on the new Query DTO")
void testExecuteWithEqualsArrayFilter() {
String filterValue1 = generateRandomUUID();
String filterValue2 = generateRandomUUID();
String filterValue3 = generateRandomUUID();
AttributeValueList.Builder attributeValueListBuilder = AttributeValueList.newBuilder();
attributeValueListBuilder.clear();
Stream.of(filterValue1, filterValue2).map(this::generateAttrValue).forEach(attributeValueListBuilder::addValues);
Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 1").putAttributes("labels", AttributeValue.newBuilder().setValueList(attributeValueListBuilder).build()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
assertNotNull(createdEntity1);
assertFalse(createdEntity1.getEntityId().trim().isEmpty());
attributeValueListBuilder.clear();
Stream.of(filterValue2, filterValue3).map(this::generateAttrValue).forEach(attributeValueListBuilder::addValues);
Entity entity2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 2").putAttributes("labels", AttributeValue.newBuilder().setValueList(attributeValueListBuilder).build()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity2 = entityDataServiceClient.upsert(entity2);
assertNotNull(createdEntity2);
assertFalse(createdEntity2.getEntityId().trim().isEmpty());
attributeValueListBuilder.clear();
Stream.of(filterValue3, filterValue1, generateRandomUUID()).map(this::generateAttrValue).forEach(attributeValueListBuilder::addValues);
Entity entity3 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 3").putAttributes("labels", AttributeValue.newBuilder().setValueList(attributeValueListBuilder).build()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity3 = entityDataServiceClient.upsert(entity3);
assertNotNull(createdEntity3);
assertFalse(createdEntity3.getEntityId().trim().isEmpty());
Entity entity4 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 4").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity4 = entityDataServiceClient.upsert(entity4);
assertNotNull(createdEntity4);
assertFalse(createdEntity4.getEntityId().trim().isEmpty());
attributeValueListBuilder.clear();
Stream.of(generateRandomUUID(), generateRandomUUID()).map(this::generateAttrValue).forEach(attributeValueListBuilder::addValues);
Entity entity5 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 5").putAttributes("labels", AttributeValue.newBuilder().setValueList(attributeValueListBuilder).build()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity5 = entityDataServiceClient.upsert(entity5);
assertNotNull(createdEntity5);
assertFalse(createdEntity5.getEntityId().trim().isEmpty());
// Filtering for a single value in an array with EQUALS should fetch all rows having the VALUE
// AS ONE OF THE ARRAY ELEMENTS
{
EntityQueryRequest queryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.SERVICE.name()).setFilter(Filter.newBuilder().setOperator(Operator.EQ).setLhs(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(API_LABELS_ATTR))).setRhs(Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setValueType(STRING).setString(filterValue1)))).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.id").build()).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.name").build()).build()).build();
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(queryRequest));
List<ResultSetChunk> list = Lists.newArrayList(resultSetChunkIterator);
assertEquals(1, list.size());
assertEquals(2, list.get(0).getRowCount());
assertEquals(0, list.get(0).getChunkId());
assertTrue(list.get(0).getIsLastChunk());
assertEquals(createdEntity1.getEntityId(), list.get(0).getRow(0).getColumn(0).getString());
assertEquals(createdEntity1.getEntityName(), list.get(0).getRow(0).getColumn(1).getString());
assertEquals(createdEntity3.getEntityId(), list.get(0).getRow(1).getColumn(0).getString());
assertEquals(createdEntity3.getEntityName(), list.get(0).getRow(1).getColumn(1).getString());
assertTrue(list.get(0).getResultSetMetadata().getColumnMetadataCount() > 0);
}
// Filtering for a list of values in an array with EQUALS should fetch only rows EXACTLY
// MATCHING the array
{
EntityQueryRequest queryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.SERVICE.name()).setFilter(Filter.newBuilder().setOperator(Operator.EQ).setLhs(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(API_LABELS_ATTR))).setRhs(Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setValueType(STRING_ARRAY).addStringArray(filterValue1).addStringArray(filterValue2)))).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.id").build()).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.name").build()).build()).build();
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(queryRequest));
List<ResultSetChunk> list = Lists.newArrayList(resultSetChunkIterator);
assertEquals(1, list.size());
assertEquals(1, list.get(0).getRowCount());
assertEquals(0, list.get(0).getChunkId());
assertTrue(list.get(0).getIsLastChunk());
assertEquals(createdEntity1.getEntityId(), list.get(0).getRow(0).getColumn(0).getString());
assertEquals(createdEntity1.getEntityName(), list.get(0).getRow(0).getColumn(1).getString());
assertTrue(list.get(0).getResultSetMetadata().getColumnMetadataCount() > 0);
}
// Filtering for a list of (order-changed) values in an array with EQUALS should fetch EMPTY
// RESULT-SET
{
EntityQueryRequest queryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.SERVICE.name()).setFilter(Filter.newBuilder().setOperator(Operator.EQ).setLhs(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName(API_LABELS_ATTR))).setRhs(Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setValueType(STRING_ARRAY).addStringArray(filterValue2).addStringArray(filterValue1)))).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.id").build()).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("API.name").build()).build()).build();
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(queryRequest));
List<ResultSetChunk> list = Lists.newArrayList(resultSetChunkIterator);
assertEquals(1, list.size());
assertEquals(0, list.get(0).getRowCount());
assertEquals(0, list.get(0).getChunkId());
assertTrue(list.get(0).getIsLastChunk());
assertTrue(list.get(0).getResultSetMetadata().getColumnMetadataCount() > 0);
}
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceTest method testBulkUpdate.
@Test
public void testBulkUpdate() throws InterruptedException {
Entity.Builder apiEntityBuilder1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.API.name()).setEntityName("api1").putIdentifyingAttributes(EntityConstants.getValue(ServiceAttribute.SERVICE_ATTRIBUTE_ID), createAttribute(SERVICE_ID)).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_NAME), createAttribute("api1")).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_API_TYPE), createAttribute(API_TYPE));
apiEntityBuilder1.putAttributes(apiAttributesMap.get(API_DISCOVERY_STATE_ATTR), createAttribute("DISCOVERED")).putAttributes(apiAttributesMap.get(API_HTTP_METHOD_ATTR), createAttribute("GET"));
Entity entity1 = entityDataServiceClient.upsert(apiEntityBuilder1.build());
Entity.Builder apiEntityBuilder2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.API.name()).setEntityName("api2").putIdentifyingAttributes(EntityConstants.getValue(ServiceAttribute.SERVICE_ATTRIBUTE_ID), createAttribute(SERVICE_ID)).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_NAME), createAttribute("api2")).putIdentifyingAttributes(EntityConstants.getValue(ApiAttribute.API_ATTRIBUTE_API_TYPE), createAttribute(API_TYPE));
apiEntityBuilder2.putAttributes(apiAttributesMap.get(API_DISCOVERY_STATE_ATTR), createAttribute("UNDER_DISCOVERY")).putAttributes(apiAttributesMap.get(API_HTTP_METHOD_ATTR), createAttribute("GET"));
Entity entity2 = entityDataServiceClient.upsert(apiEntityBuilder2.build());
// create BulkUpdate request
UpdateOperation update1 = UpdateOperation.newBuilder().setSetAttribute(SetAttribute.newBuilder().setAttribute(ColumnIdentifier.newBuilder().setColumnName(API_DISCOVERY_STATE_ATTR)).setValue(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setString("DISCOVERED")))).build();
UpdateOperation update2 = UpdateOperation.newBuilder().setSetAttribute(SetAttribute.newBuilder().setAttribute(ColumnIdentifier.newBuilder().setColumnName(API_HTTP_METHOD_ATTR)).setValue(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setString("POST")))).build();
EntityUpdateInfo updateInfo1 = EntityUpdateInfo.newBuilder().addUpdateOperation(update2).build();
EntityUpdateInfo updateInfo2 = EntityUpdateInfo.newBuilder().addUpdateOperation(update1).addUpdateOperation(update2).build();
BulkEntityUpdateRequest bulkUpdateRequest = BulkEntityUpdateRequest.newBuilder().setEntityType(EntityType.API.name()).putEntities(entity1.getEntityId(), updateInfo1).putEntities(entity2.getEntityId(), updateInfo2).build();
Iterator<ResultSetChunk> iterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.bulkUpdate(bulkUpdateRequest));
while (iterator.hasNext()) {
continue;
}
// Add a small delay for the update to reflect
Thread.sleep(500);
EntityQueryRequest entityQueryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.API.name()).addSelection(createExpression(API_DISCOVERY_STATE_ATTR)).addSelection(createExpression(API_HTTP_METHOD_ATTR)).build();
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(entityQueryRequest));
List<String> values = new ArrayList<>();
while (resultSetChunkIterator.hasNext()) {
ResultSetChunk chunk = resultSetChunkIterator.next();
for (Row row : chunk.getRowList()) {
for (int i = 0; i < row.getColumnCount(); i++) {
String value = row.getColumnList().get(i).getString();
values.add(value);
}
}
}
assertEquals(4, values.size());
assertEquals("DISCOVERED", values.get(0));
assertEquals("POST", values.get(1));
assertEquals("DISCOVERED", values.get(2));
assertEquals("POST", values.get(3));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceTest method testExecute.
@Test
public void testExecute() {
// create and upsert some entities
Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 1").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
assertNotNull(createdEntity1);
assertFalse(createdEntity1.getEntityId().trim().isEmpty());
Entity entity2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 2").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity2 = entityDataServiceClient.upsert(entity2);
assertNotNull(createdEntity2);
assertFalse(createdEntity2.getEntityId().trim().isEmpty());
Entity entity3 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 3").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity3 = entityDataServiceClient.upsert(entity3);
assertNotNull(createdEntity3);
assertFalse(createdEntity3.getEntityId().trim().isEmpty());
Entity entity4 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 4").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity4 = entityDataServiceClient.upsert(entity4);
assertNotNull(createdEntity4);
assertFalse(createdEntity4.getEntityId().trim().isEmpty());
Entity entity5 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 5").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity5 = entityDataServiceClient.upsert(entity5);
assertNotNull(createdEntity5);
assertFalse(createdEntity5.getEntityId().trim().isEmpty());
EntityQueryRequest queryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.SERVICE.name()).setFilter(Filter.newBuilder().setOperatorValue(Operator.LT.getNumber()).setLhs(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("SERVICE.createdTime").build()).build()).setRhs(Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(org.hypertrace.entity.query.service.v1.Value.newBuilder().setLong(Instant.now().toEpochMilli()).setValueType(ValueType.LONG).build()).build()).build()).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("SERVICE.id").build()).build()).addSelection(Expression.newBuilder().setColumnIdentifier(ColumnIdentifier.newBuilder().setColumnName("SERVICE.name").build()).build()).build();
// this entity will be filtered out
Entity entity6 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.SERVICE.name()).setEntityName("Some Service 6").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), generateRandomUUIDAttrValue()).build();
Entity createdEntity6 = entityDataServiceClient.upsert(entity6);
assertNotNull(createdEntity6);
assertFalse(createdEntity6.getEntityId().trim().isEmpty());
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(queryRequest));
List<ResultSetChunk> list = Lists.newArrayList(resultSetChunkIterator);
assertEquals(3, list.size());
assertEquals(2, list.get(0).getRowCount());
assertEquals(0, list.get(0).getChunkId());
assertFalse(list.get(0).getIsLastChunk());
assertEquals(2, list.get(1).getRowCount());
assertEquals(1, list.get(1).getChunkId());
assertFalse(list.get(1).getIsLastChunk());
assertEquals(1, list.get(2).getRowCount());
assertEquals(2, list.get(2).getChunkId());
assertTrue(list.get(2).getIsLastChunk());
assertEquals(createdEntity1.getEntityId(), list.get(0).getRow(0).getColumn(0).getString());
assertEquals(createdEntity1.getEntityName(), list.get(0).getRow(0).getColumn(1).getString());
assertEquals(createdEntity2.getEntityId(), list.get(0).getRow(1).getColumn(0).getString());
assertEquals(createdEntity2.getEntityName(), list.get(0).getRow(1).getColumn(1).getString());
assertEquals(createdEntity3.getEntityId(), list.get(1).getRow(0).getColumn(0).getString());
assertEquals(createdEntity3.getEntityName(), list.get(1).getRow(0).getColumn(1).getString());
assertEquals(createdEntity4.getEntityId(), list.get(1).getRow(1).getColumn(0).getString());
assertEquals(createdEntity4.getEntityName(), list.get(1).getRow(1).getColumn(1).getString());
assertEquals(createdEntity5.getEntityId(), list.get(2).getRow(0).getColumn(0).getString());
assertEquals(createdEntity5.getEntityName(), list.get(2).getRow(0).getColumn(1).getString());
// metadata sent for each chunk
assertTrue(list.get(0).getResultSetMetadata().getColumnMetadataCount() > 0);
assertTrue(list.get(1).getResultSetMetadata().getColumnMetadataCount() > 0);
assertTrue(list.get(2).getResultSetMetadata().getColumnMetadataCount() > 0);
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityQueryServiceTest method testCreateAndGetEntities.
@Test
public void testCreateAndGetEntities() {
// creating an api entity with attributes
Entity.Builder apiEntityBuilder1 = createApiEntity(SERVICE_ID, "api1", API_TYPE);
apiEntityBuilder1.putAttributes(apiAttributesMap.get(API_DISCOVERY_STATE_ATTR), createAttribute("DISCOVERED")).putAttributes(apiAttributesMap.get(API_HTTP_METHOD_ATTR), createAttribute("GET"));
entityDataServiceClient.upsert(apiEntityBuilder1.build());
Entity.Builder apiEntityBuilder2 = createApiEntity(SERVICE_ID, "api2", API_TYPE);
apiEntityBuilder2.putAttributes(apiAttributesMap.get(API_DISCOVERY_STATE_ATTR), createAttribute("UNDER_DISCOVERY")).putAttributes(apiAttributesMap.get(API_HTTP_METHOD_ATTR), createAttribute("GET"));
entityDataServiceClient.upsert(apiEntityBuilder2.build());
// querying the api entity
EntityQueryRequest entityQueryRequest = EntityQueryRequest.newBuilder().setEntityType(EntityType.API.name()).addSelection(createExpression(API_DISCOVERY_STATE_ATTR)).build();
Iterator<ResultSetChunk> resultSetChunkIterator = GrpcClientRequestContextUtil.executeWithHeadersContext(HEADERS, () -> entityQueryServiceClient.execute(entityQueryRequest));
List<String> values = new ArrayList<>();
while (resultSetChunkIterator.hasNext()) {
ResultSetChunk chunk = resultSetChunkIterator.next();
for (Row row : chunk.getRowList()) {
for (int i = 0; i < row.getColumnCount(); i++) {
String value = row.getColumnList().get(i).getString();
values.add(value);
}
}
}
assertEquals(2, values.size());
assertEquals("DISCOVERED", values.get(0));
assertEquals("UNDER_DISCOVERY", values.get(1));
}
Aggregations