use of com.sequenceiq.periscope.domain.LoadAlert in project cloudbreak by hortonworks.
the class ScalingHandlerTest method testOnApplicationEventWhenLoadAlertDecommissionNodes.
@Test
public void testOnApplicationEventWhenLoadAlertDecommissionNodes() {
LoadAlert loadAlertMock = mock(LoadAlert.class);
Cluster cluster = getARunningCluster();
int clusterNodeSize = 100;
int hostGroupNodeCount = 10;
List nodeIds = List.of("nodeId1", "nodeId2", "nodeId3");
int expectedNodeCount = hostGroupNodeCount - nodeIds.size();
when(scalingEventMock.getAlert()).thenReturn(loadAlertMock);
when(loadAlertMock.getCluster()).thenReturn(cluster);
when(loadAlertMock.getScalingPolicy()).thenReturn(scalingPolicyMock);
when(clusterService.findById(anyLong())).thenReturn(cluster);
when(scalingPolicyMock.getAdjustmentType()).thenReturn(LOAD_BASED);
when(scalingEventMock.getExistingClusterNodeCount()).thenReturn(clusterNodeSize);
when(scalingEventMock.getExistingHostGroupNodeCount()).thenReturn(hostGroupNodeCount);
when(scalingEventMock.getDesiredAbsoluteHostGroupNodeCount()).thenReturn(expectedNodeCount);
when(scalingEventMock.getDecommissionNodeIds()).thenReturn(nodeIds);
when(applicationContext.getBean("ScalingRequest", cluster, scalingPolicyMock, clusterNodeSize, hostGroupNodeCount, expectedNodeCount, nodeIds)).thenReturn(runnableMock);
underTest.onApplicationEvent(scalingEventMock);
verify(rejectedThreadService).remove(AUTOSCALE_CLUSTER_ID);
verify(clusterService).setLastScalingActivity(eq(AUTOSCALE_CLUSTER_ID), anyLong());
verify(executorService).submit(runnableMock);
}
use of com.sequenceiq.periscope.domain.LoadAlert in project cloudbreak by hortonworks.
the class ClusterRepositoryTest method getAClusterWithLoadAlerts.
private Cluster getAClusterWithLoadAlerts() {
Cluster cluster = new Cluster();
cluster.setStackCrn(CLOUDBREAK_STACK_CRN_1);
cluster.setState(ClusterState.RUNNING);
cluster.setAutoscalingEnabled(Boolean.TRUE);
cluster.setStackType(StackType.WORKLOAD);
ClusterPertain clusterPertain = new ClusterPertain();
clusterPertain.setTenant(TEST_TENANT);
cluster.setClusterPertain(clusterPertain);
ScalingPolicy scalingPolicy = new ScalingPolicy();
scalingPolicy.setAdjustmentType(AdjustmentType.LOAD_BASED);
scalingPolicy.setHostGroup("compute");
LoadAlertConfiguration alertConfiguration = new LoadAlertConfiguration();
alertConfiguration.setCoolDownMinutes(10);
alertConfiguration.setMaxResourceValue(TEST_HOSTGROUP_MAX_SIZE);
alertConfiguration.setMinResourceValue(TEST_HOSTGROUP_MIN_SIZE);
LoadAlert loadAlert = new LoadAlert();
loadAlert.setScalingPolicy(scalingPolicy);
loadAlert.setLoadAlertConfiguration(alertConfiguration);
loadAlert.setCluster(cluster);
cluster.setLoadAlerts(Set.of(loadAlert));
cluster.setLastScalingActivity(Instant.now().minus(45, ChronoUnit.MINUTES).toEpochMilli());
return cluster;
}
use of com.sequenceiq.periscope.domain.LoadAlert in project cloudbreak by hortonworks.
the class AlertServiceTest method testCreateLoadAlert.
@Test
public void testCreateLoadAlert() {
Long clusterId = 10L;
LoadAlert testAlert = getLoadAlert();
when(clusterService.findById(clusterId)).thenReturn(mockCluster);
when(clusterService.save(mockCluster)).thenReturn(mockCluster);
when(loadAlertRepository.save(testAlert)).thenReturn(mockLoadAlert);
LoadAlert response = doAs(TEST_USER_CRN, () -> underTest.createLoadAlert(clusterId, testAlert));
assertNotNull("LoadAlert should not be null", response);
assertNotNull("LoadAlert' cluster should not be null", testAlert.getCluster());
verify(loadAlertRepository).save(any(LoadAlert.class));
verify(clusterService).findById(clusterId);
verify(clusterService).save(mockCluster);
}
use of com.sequenceiq.periscope.domain.LoadAlert in project cloudbreak by hortonworks.
the class AlertServiceTest method getLoadAlert.
private LoadAlert getLoadAlert() {
LoadAlert testAlert = new LoadAlert();
testAlert.setName("test");
testAlert.setDescription("test desc");
testAlert.setScalingPolicy(getScalingPolicy());
return testAlert;
}
use of com.sequenceiq.periscope.domain.LoadAlert in project cloudbreak by hortonworks.
the class YarnLoadEvaluatorTest method getARunningCluster.
private Cluster getARunningCluster() {
Cluster cluster = new Cluster();
cluster.setId(AUTOSCALE_CLUSTER_ID);
cluster.setStackCrn(CLOUDBREAK_STACK_CRN);
cluster.setState(ClusterState.RUNNING);
ClusterPertain clusterPertain = new ClusterPertain();
clusterPertain.setTenant("testtenant");
cluster.setClusterPertain(clusterPertain);
ScalingPolicy scalingPolicy = new ScalingPolicy();
scalingPolicy.setAdjustmentType(AdjustmentType.LOAD_BASED);
scalingPolicy.setHostGroup("compute");
LoadAlertConfiguration alertConfiguration = new LoadAlertConfiguration();
alertConfiguration.setCoolDownMinutes(10);
alertConfiguration.setMaxResourceValue(TEST_HOSTGROUP_MAX_SIZE);
alertConfiguration.setMinResourceValue(TEST_HOSTGROUP_MIN_SIZE);
LoadAlert loadAlert = new LoadAlert();
loadAlert.setScalingPolicy(scalingPolicy);
loadAlert.setLoadAlertConfiguration(alertConfiguration);
cluster.setLoadAlerts(Set.of(loadAlert));
cluster.setLastScalingActivity(Instant.now().minus(45, ChronoUnit.MINUTES).toEpochMilli());
cluster.setMachineUserCrn(MACHINE_USER_CNR);
return cluster;
}
Aggregations