Search in sources :

Example 1 with ProfileResponse

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());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) ProfileAction(org.opensearch.ad.transport.ProfileAction) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) ActionListener(org.opensearch.action.ActionListener) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException)

Example 2 with ProfileResponse

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());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) ProfileAction(org.opensearch.ad.transport.ProfileAction) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) ActionListener(org.opensearch.action.ActionListener) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException)

Example 3 with ProfileResponse

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));
}
Also used : Arrays(java.util.Arrays) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) Version(org.opensearch.Version) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ANOMALY_DETECTOR_JOB_INDEX(org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) RCFPollingAction(org.opensearch.ad.transport.RCFPollingAction) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) DetectorProfile(org.opensearch.ad.model.DetectorProfile) RemoteTransportException(org.opensearch.transport.RemoteTransportException) Set(java.util.Set) Instant(java.time.Instant) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DetectorState(org.opensearch.ad.model.DetectorState) DetectorInternalState(org.opensearch.ad.model.DetectorInternalState) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper) ADTask(org.opensearch.ad.model.ADTask) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ModelProfileOnNode(org.opensearch.ad.model.ModelProfileOnNode) ArrayList(java.util.ArrayList) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) Collections.emptyMap(java.util.Collections.emptyMap) CommonName(org.opensearch.ad.constant.CommonName) Collections.emptySet(java.util.Collections.emptySet) FailedNodeException(org.opensearch.action.FailedNodeException) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RCFPollingResponse(org.opensearch.ad.transport.RCFPollingResponse) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) ChronoUnit(java.time.temporal.ChronoUnit) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) ClusterName(org.opensearch.cluster.ClusterName) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) Collections(java.util.Collections) ProfileAction(org.opensearch.ad.transport.ProfileAction) ModelProfileOnNode(org.opensearch.ad.model.ModelProfileOnNode) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with ProfileResponse

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);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) ModelProfileOnNode(org.opensearch.ad.model.ModelProfileOnNode) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) EntityProfileResponse(org.opensearch.ad.transport.EntityProfileResponse) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) ModelProfile(org.opensearch.ad.model.ModelProfile) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException)

Example 5 with ProfileResponse

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()));
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) EntityProfileResponse(org.opensearch.ad.transport.EntityProfileResponse) ProfileResponse(org.opensearch.ad.transport.ProfileResponse)

Aggregations

ProfileResponse (org.opensearch.ad.transport.ProfileResponse)7 ProfileNodeResponse (org.opensearch.ad.transport.ProfileNodeResponse)5 ClusterName (org.opensearch.cluster.ClusterName)5 HashMap (java.util.HashMap)4 ActionListener (org.opensearch.action.ActionListener)4 FailedNodeException (org.opensearch.action.FailedNodeException)4 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)4 TransportAddress (org.opensearch.common.transport.TransportAddress)4 ModelProfileOnNode (org.opensearch.ad.model.ModelProfileOnNode)3 EntityProfileResponse (org.opensearch.ad.transport.EntityProfileResponse)3 ProfileAction (org.opensearch.ad.transport.ProfileAction)3 StreamInput (org.opensearch.common.io.stream.StreamInput)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1