use of org.opensearch.ad.transport.ProfileResponse in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method setUpClientExecuteProfileAction.
@SuppressWarnings("unchecked")
private void setUpClientExecuteProfileAction() {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<ProfileResponse> listener = (ActionListener<ProfileResponse>) args[2];
node1 = "node1";
nodeName1 = "nodename1";
discoveryNode1 = new DiscoveryNode(nodeName1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
node2 = "node2";
nodeName2 = "nodename2";
discoveryNode2 = new DiscoveryNode(nodeName2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), Version.CURRENT);
modelSize = 4456448L;
model1Id = "Pl536HEBnXkDrah03glg_model_rcf_1";
model0Id = "Pl536HEBnXkDrah03glg_model_rcf_0";
shingleSize = 6;
String clusterName = "test-cluster-name";
Map<String, Long> modelSizeMap1 = new HashMap<String, Long>() {
{
put(model1Id, modelSize);
}
};
Map<String, Long> modelSizeMap2 = new HashMap<String, Long>() {
{
put(model0Id, modelSize);
}
};
ProfileNodeResponse profileNodeResponse1 = new ProfileNodeResponse(discoveryNode1, modelSizeMap1, shingleSize, 0L, 0L, new ArrayList<>(), modelSizeMap1.size());
ProfileNodeResponse profileNodeResponse2 = new ProfileNodeResponse(discoveryNode2, modelSizeMap2, -1, 0L, 0L, new ArrayList<>(), modelSizeMap2.size());
List<ProfileNodeResponse> profileNodeResponses = Arrays.asList(profileNodeResponse1, profileNodeResponse2);
List<FailedNodeException> failures = Collections.emptyList();
ProfileResponse profileResponse = new ProfileResponse(new ClusterName(clusterName), profileNodeResponses, failures);
listener.onResponse(profileResponse);
return null;
}).when(client).execute(any(ProfileAction.class), any(), any());
}
use of org.opensearch.ad.transport.ProfileResponse in project anomaly-detection by opensearch-project.
the class MultiEntityProfileRunnerTests method setUpClientExecuteProfileAction.
@SuppressWarnings("unchecked")
private void setUpClientExecuteProfileAction(InittedEverResultStatus initted) {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<ProfileResponse> listener = (ActionListener<ProfileResponse>) args[2];
node1 = "node1";
nodeName1 = "nodename1";
discoveryNode1 = new DiscoveryNode(nodeName1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
node2 = "node2";
nodeName2 = "nodename2";
discoveryNode2 = new DiscoveryNode(nodeName2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), Version.CURRENT);
modelSize = 712480L;
model1Id = "A69pa3UBHuCbh-emo9oR_entity_host1";
model0Id = "A69pa3UBHuCbh-emo9oR_entity_host0";
shingleSize = -1;
String clusterName = "test-cluster-name";
Map<String, Long> modelSizeMap1 = new HashMap<String, Long>() {
{
put(model1Id, modelSize);
}
};
Map<String, Long> modelSizeMap2 = new HashMap<String, Long>() {
{
put(model0Id, modelSize);
}
};
// one model in each node; all fully initialized
long updates = requiredSamples - 1;
if (InittedEverResultStatus.INITTED == initted) {
updates = requiredSamples + 1;
}
ProfileNodeResponse profileNodeResponse1 = new ProfileNodeResponse(discoveryNode1, modelSizeMap1, shingleSize, 1L, updates, new ArrayList<>(), modelSizeMap1.size());
ProfileNodeResponse profileNodeResponse2 = new ProfileNodeResponse(discoveryNode2, modelSizeMap2, shingleSize, 1L, updates, new ArrayList<>(), modelSizeMap2.size());
List<ProfileNodeResponse> profileNodeResponses = Arrays.asList(profileNodeResponse1, profileNodeResponse2);
List<FailedNodeException> failures = Collections.emptyList();
ProfileResponse profileResponse = new ProfileResponse(new ClusterName(clusterName), profileNodeResponses, failures);
listener.onResponse(profileResponse);
return null;
}).when(client).execute(any(ProfileAction.class), any(), any());
}
use of org.opensearch.ad.transport.ProfileResponse 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.transport.ProfileResponse 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.transport.ProfileResponse in project anomaly-detection by opensearch-project.
the class BwcTests method testDeserializeProfileResponse1_1.
/**
* For ProfileResponse, the input is a 1.1 stream.
* @throws IOException when serialization/deserialization has issues.
*/
public void testDeserializeProfileResponse1_1() throws IOException {
setUpProfileResponse();
profileResponse1_1.writeTo(output1_1);
StreamInput streamInput = output1_1.bytes().streamInput();
streamInput.setVersion(V_1_1_0);
ProfileResponse readResponse = new ProfileResponse(streamInput);
assertThat(readResponse.getModelProfile(), equalTo(profileResponse1_1.getModelProfile()));
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(profileResponse1_1.getModelCount()));
}
Aggregations