use of org.opensearch.ad.model.ModelProfile in project anomaly-detection by opensearch-project.
the class EntityProfileRunnerTests method testModel.
public void testModel() throws InterruptedException {
setUpExecuteEntityProfileAction(InittedEverResultStatus.INITTED);
EntityProfile.Builder expectedProfile = new EntityProfile.Builder();
ModelProfileOnNode modelProfile = new ModelProfileOnNode(nodeId, new ModelProfile(modelId, entity, modelSize));
expectedProfile.modelProfile(modelProfile);
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detectorId, entity, model, ActionListener.wrap(response -> {
assertEquals(expectedProfile.build(), response);
inProgressLatch.countDown();
}, exception -> {
assertTrue("Should not reach here", false);
inProgressLatch.countDown();
}));
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.ModelProfile in project anomaly-detection by opensearch-project.
the class EntityProfileRunnerTests method setUpExecuteEntityProfileAction.
@SuppressWarnings("unchecked")
private void setUpExecuteEntityProfileAction(InittedEverResultStatus initted) {
smallUpdates = 1;
latestActiveTimestamp = 1603999189758L;
isActive = Boolean.TRUE;
modelId = "T4c3dXUBj-2IZN7itix__entity_" + entityValue;
modelSize = 712480L;
nodeId = "g6pmr547QR-CfpEvO67M4g";
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<EntityProfileResponse> listener = (ActionListener<EntityProfileResponse>) args[2];
EntityProfileResponse.Builder profileResponseBuilder = new EntityProfileResponse.Builder();
if (InittedEverResultStatus.UNKNOWN == initted) {
profileResponseBuilder.setTotalUpdates(0L);
} else if (InittedEverResultStatus.NOT_INITTED == initted) {
profileResponseBuilder.setTotalUpdates(smallUpdates);
profileResponseBuilder.setLastActiveMs(latestActiveTimestamp);
profileResponseBuilder.setActive(isActive);
} else {
profileResponseBuilder.setTotalUpdates(requiredSamples + 1);
ModelProfileOnNode model = new ModelProfileOnNode(nodeId, new ModelProfile(modelId, entity, modelSize));
profileResponseBuilder.setModelProfile(model);
}
listener.onResponse(profileResponseBuilder.build());
return null;
}).when(client).execute(any(EntityProfileAction.class), any(), any());
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
SearchRequest request = (SearchRequest) args[0];
String indexName = request.indices()[0];
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
SearchResponse searchResponse = null;
if (indexName.equals(CommonName.ANOMALY_RESULT_INDEX_ALIAS)) {
InternalMax maxAgg = new InternalMax(CommonName.AGG_NAME_MAX_TIME, latestSampleTimestamp, DocValueFormat.RAW, emptyMap());
InternalAggregations internalAggregations = InternalAggregations.from(Collections.singletonList(maxAgg));
SearchHits hits = new SearchHits(new SearchHit[] {}, null, Float.NaN);
SearchResponseSections searchSections = new SearchResponseSections(hits, internalAggregations, null, false, false, null, 1);
searchResponse = new SearchResponse(searchSections, null, 1, 1, 0, 30, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY);
} else {
SearchHits collapsedHits = new SearchHits(new SearchHit[] { new SearchHit(2, "ID", new Text("type"), Collections.emptyMap(), Collections.emptyMap()), new SearchHit(3, "ID", new Text("type"), Collections.emptyMap(), Collections.emptyMap()) }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0F);
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(collapsedHits, null, null, null, false, null, 1);
searchResponse = new SearchResponse(internalSearchResponse, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY);
}
listener.onResponse(searchResponse);
return null;
}).when(client).search(any(), any());
}
use of org.opensearch.ad.model.ModelProfile in project anomaly-detection by opensearch-project.
the class BwcTests method setUpEntityProfileResponse.
private void setUpEntityProfileResponse() {
long lastActiveTimestamp = 10L;
EntityProfileResponse.Builder builder = new EntityProfileResponse.Builder();
builder.setLastActiveMs(lastActiveTimestamp).build();
ModelProfile modelProfile = new ModelProfile(modelId, entity, modelSize);
ModelProfileOnNode model = new ModelProfileOnNode(nodeId, modelProfile);
builder.setModelProfile(model);
entityProfileResponse1_1 = builder.build();
EntityProfileResponse1_0.Builder builder1_0 = new EntityProfileResponse1_0.Builder();
builder1_0.setLastActiveMs(lastActiveTimestamp).build();
ModelProfile1_0 modelProfile1_0 = new ModelProfile1_0(modelId, modelSize, nodeId);
builder1_0.setModelProfile(modelProfile1_0);
entityProfileResponse1_0 = builder1_0.build();
ModelProfile convertedModelProfile = new ModelProfile(modelId, null, modelSize);
convertedModelProfileOnNode = new ModelProfileOnNode(CommonName.EMPTY_FIELD, convertedModelProfile);
}
use of org.opensearch.ad.model.ModelProfile in project anomaly-detection by opensearch-project.
the class BwcTests method setUpProfileResponse.
@SuppressWarnings("serial")
private void setUpProfileResponse() {
String node1 = "node1";
String nodeName1 = "nodename1";
DiscoveryNode discoveryNode1_1 = new DiscoveryNode(nodeName1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), V_1_1_0);
String node2 = "node2";
String nodeName2 = "nodename2";
DiscoveryNode discoveryNode2 = new DiscoveryNode(nodeName2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), V_1_1_0);
String model1Id = "model1";
String model2Id = "model2";
Map<String, Long> modelSizeMap1 = new HashMap<String, Long>() {
{
put(model1Id, modelSize);
put(model2Id, modelSize2);
}
};
Map<String, Long> modelSizeMap2 = new HashMap<String, Long>();
int shingleSize = 8;
ModelProfile modelProfile = new ModelProfile(model1Id, entity, modelSize);
ModelProfile modelProfile2 = new ModelProfile(model2Id, entity2, modelSize2);
ProfileNodeResponse profileNodeResponse1 = new ProfileNodeResponse(discoveryNode1_1, modelSizeMap1, shingleSize, 0, 0, Arrays.asList(modelProfile, modelProfile2), modelSizeMap1.size());
ProfileNodeResponse profileNodeResponse2 = new ProfileNodeResponse(discoveryNode2, modelSizeMap2, -1, 0, 0, new ArrayList<>(), modelSizeMap2.size());
List<ProfileNodeResponse> profileNodeResponses = Arrays.asList(profileNodeResponse1, profileNodeResponse2);
List<FailedNodeException> failures = Collections.emptyList();
ClusterName clusterName = new ClusterName("test-cluster-name");
profileResponse1_1 = new ProfileResponse(clusterName, profileNodeResponses, failures);
ProfileNodeResponse1_0 profileNodeResponse1_1_0 = new ProfileNodeResponse1_0(discoveryNode1_1, modelSizeMap1, shingleSize, 0, 0);
ProfileNodeResponse1_0 profileNodeResponse2_1_0 = new ProfileNodeResponse1_0(discoveryNode2, modelSizeMap2, -1, 0, 0);
List<ProfileNodeResponse1_0> profileNodeResponses1_0 = Arrays.asList(profileNodeResponse1_1_0, profileNodeResponse2_1_0);
profileResponse1_0 = new ProfileResponse1_0(clusterName, profileNodeResponses1_0, failures);
convertedModelProfileOnNodeArray = new ModelProfileOnNode[2];
ModelProfile convertedModelProfile1 = new ModelProfile(model1Id, null, modelSize);
convertedModelProfileOnNodeArray[0] = new ModelProfileOnNode(CommonName.EMPTY_FIELD, convertedModelProfile1);
ModelProfile convertedModelProfile2 = new ModelProfile(model2Id, null, modelSize2);
convertedModelProfileOnNodeArray[1] = new ModelProfileOnNode(CommonName.EMPTY_FIELD, convertedModelProfile2);
convertedModelProfile = new ModelProfile1_0[2];
convertedModelProfile[0] = new ModelProfile1_0(model1Id, modelSize, CommonName.EMPTY_FIELD);
convertedModelProfile[1] = new ModelProfile1_0(model2Id, modelSize2, CommonName.EMPTY_FIELD);
}
use of org.opensearch.ad.model.ModelProfile in project anomaly-detection by opensearch-project.
the class EntityProfileTests method testResponseHashCodeEquals.
public void testResponseHashCodeEquals() {
EntityProfileResponse.Builder builder = new EntityProfileResponse.Builder();
builder.setLastActiveMs(lastActiveTimestamp).build();
ModelProfileOnNode model = new ModelProfileOnNode(nodeId, new ModelProfile(modelId, entity, modelSize));
builder.setModelProfile(model);
EntityProfileResponse response = builder.build();
HashSet<EntityProfileResponse> set = new HashSet<>();
assertTrue(false == set.contains(response));
set.add(response);
assertTrue(set.contains(response));
}
Aggregations