use of org.opensearch.ad.model.ModelProfileOnNode in project anomaly-detection by opensearch-project.
the class ProfileResponse method toXContent.
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(COORDINATING_NODE, coordinatingNode);
builder.field(SHINGLE_SIZE, shingleSize);
builder.field(TOTAL_SIZE, totalSizeInBytes);
builder.field(ACTIVE_ENTITY, activeEntities);
builder.field(TOTAL_UPDATES, totalUpdates);
if (modelCount > 0) {
builder.field(MODEL_COUNT, modelCount);
}
builder.startArray(MODELS);
for (ModelProfileOnNode profile : modelProfile) {
profile.toXContent(builder, params);
}
builder.endArray();
return builder;
}
use of org.opensearch.ad.model.ModelProfileOnNode in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testProfileModels.
public void testProfileModels() throws InterruptedException, IOException {
setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, RCFPollingStatus.EMPTY, ErrorResultStatus.NO_ERROR);
setUpClientExecuteProfileAction();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(profileResponse -> {
assertEquals(node1, profileResponse.getCoordinatingNode());
assertEquals(shingleSize, profileResponse.getShingleSize());
assertEquals(modelSize * 2, profileResponse.getTotalSizeInBytes());
assertEquals(2, profileResponse.getModelProfile().length);
for (ModelProfileOnNode profile : profileResponse.getModelProfile()) {
assertTrue(node1.equals(profile.getNodeId()) || node2.equals(profile.getNodeId()));
assertEquals(modelSize, profile.getModelSize());
if (node1.equals(profile.getNodeId())) {
assertEquals(model1Id, profile.getModelId());
}
if (node2.equals(profile.getNodeId())) {
assertEquals(model0Id, profile.getModelId());
}
}
inProgressLatch.countDown();
}, exception -> {
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}), modelProfile);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.ModelProfileOnNode 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.ModelProfileOnNode in project anomaly-detection by opensearch-project.
the class BwcTests method testDeserializeProfileResponse1_0.
/**
* For ProfileResponse, the input is a 1.0 stream.
* @throws IOException when serialization/deserialization has issues.
*/
public void testDeserializeProfileResponse1_0() throws IOException {
setUpProfileResponse();
profileResponse1_0.writeTo(output1_0);
StreamInput streamInput = output1_0.bytes().streamInput();
streamInput.setVersion(Version.V_1_0_0);
ProfileResponse readResponse = new ProfileResponse(streamInput);
ModelProfileOnNode[] actualModelProfileOnNode = readResponse.getModelProfile();
// since ProfileResponse1_0's constructor iterates modelSize and modelSize is
// a HashMap. The iteration order is not deterministic. We have to sort the
// results in an ordered fashion to compare with expected value.
Arrays.sort(actualModelProfileOnNode, new Comparator<ModelProfileOnNode>() {
@Override
public int compare(ModelProfileOnNode o1, ModelProfileOnNode o2) {
return o1.getModelId().compareTo(o2.getModelId());
}
});
assertThat(actualModelProfileOnNode, equalTo(convertedModelProfileOnNodeArray));
assertThat(readResponse.getShingleSize(), equalTo(profileResponse1_1.getShingleSize()));
assertThat(readResponse.getActiveEntities(), equalTo(profileResponse1_1.getActiveEntities()));
assertThat(readResponse.getTotalUpdates(), equalTo(profileResponse1_1.getTotalUpdates()));
assertThat(readResponse.getCoordinatingNode(), equalTo(profileResponse1_1.getCoordinatingNode()));
assertThat(readResponse.getTotalSizeInBytes(), equalTo(profileResponse1_1.getTotalSizeInBytes()));
assertThat(readResponse.getModelCount(), equalTo(0L));
}
use of org.opensearch.ad.model.ModelProfileOnNode 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