use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.
the class ADClusterEventListenerTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
super.setUpLog4jForJUnit(ADClusterEventListener.class);
clusterService = createClusterService(threadPool);
hashRing = mock(HashRing.class);
masterNode = new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT);
oldClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(masterNodeId).add(masterNode)).build();
newClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)).build();
listener = new ADClusterEventListener(clusterService, hashRing);
}
use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.
the class ADClusterEventListenerTests method testNotRecovered.
public void testNotRecovered() {
ClusterState blockedClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)).blocks(ClusterBlocks.builder().addGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)).build();
listener.clusterChanged(new ClusterChangedEvent("foo", blockedClusterState, oldClusterState));
assertTrue(testAppender.containsMessage(ADClusterEventListener.NOT_RECOVERED_MSG));
}
use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.
the class ADClusterEventListenerTests method testNodeRemoved.
public void testNodeRemoved() {
ClusterState twoDataNodeClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)).add(dataNode1).add(new DiscoveryNode("dataNode2", buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT))).build();
listener.clusterChanged(new ClusterChangedEvent("foo", newClusterState, twoDataNodeClusterState));
assertTrue(testAppender.containsMessage(ADClusterEventListener.NODE_CHANGED_MSG));
assertTrue(testAppender.containsMessage("node removed: true, node added: true"));
}
use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.
the class HourlyCronTests method templateHourlyCron.
@SuppressWarnings("unchecked")
public void templateHourlyCron(HourlyCronTestExecutionMode mode) {
super.setUpLog4jForJUnit(HourlyCron.class);
ClusterService clusterService = mock(ClusterService.class);
ClusterState state = ClusterCreation.state(1);
when(clusterService.state()).thenReturn(state);
HashMap<String, String> ignoredAttributes = new HashMap<String, String>();
ignoredAttributes.put(CommonName.BOX_TYPE_KEY, CommonName.WARM_BOX_TYPE);
DiscoveryNodeFilterer nodeFilter = new DiscoveryNodeFilterer(clusterService);
Client client = mock(Client.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
assertTrue(String.format("The size of args is %d. Its content is %s", args.length, Arrays.toString(args)), args.length == 3);
assertTrue(args[2] instanceof ActionListener);
ActionListener<CronResponse> listener = (ActionListener<CronResponse>) args[2];
if (mode == HourlyCronTestExecutionMode.NODE_FAIL) {
listener.onResponse(new CronResponse(new ClusterName("test"), Collections.singletonList(new CronNodeResponse(state.nodes().getLocalNode())), Collections.singletonList(new FailedNodeException("foo0", "blah", new OpenSearchException("bar")))));
} else if (mode == HourlyCronTestExecutionMode.ALL_FAIL) {
listener.onFailure(new OpenSearchException("bar"));
} else {
CronNodeResponse nodeResponse = new CronNodeResponse(state.nodes().getLocalNode());
BytesStreamOutput nodeResponseOut = new BytesStreamOutput();
nodeResponseOut.setVersion(Version.CURRENT);
nodeResponse.writeTo(nodeResponseOut);
StreamInput siNode = nodeResponseOut.bytes().streamInput();
CronNodeResponse nodeResponseRead = new CronNodeResponse(siNode);
CronResponse response = new CronResponse(new ClusterName("test"), Collections.singletonList(nodeResponseRead), Collections.EMPTY_LIST);
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(Version.CURRENT);
response.writeTo(out);
StreamInput si = out.bytes().streamInput();
CronResponse responseRead = new CronResponse(si);
listener.onResponse(responseRead);
}
return null;
}).when(client).execute(eq(CronAction.INSTANCE), any(), any());
HourlyCron cron = new HourlyCron(client, nodeFilter);
cron.run();
Logger LOG = LogManager.getLogger(HourlyCron.class);
LOG.info(testAppender.messages);
if (mode == HourlyCronTestExecutionMode.NODE_FAIL) {
assertTrue(testAppender.containsMessage(HourlyCron.NODE_EXCEPTION_LOG_MSG));
} else if (mode == HourlyCronTestExecutionMode.ALL_FAIL) {
assertTrue(testAppender.containsMessage(HourlyCron.EXCEPTION_LOG_MSG));
} else {
assertTrue(testAppender.containsMessage(HourlyCron.SUCCEEDS_LOG_MSG));
}
super.tearDownLog4jForJUnit();
}
use of org.opensearch.cluster.ClusterName 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());
}
Aggregations