Search in sources :

Example 1 with LoadAlert

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);
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) List(java.util.List) LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with LoadAlert

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;
}
Also used : ClusterPertain(com.sequenceiq.periscope.domain.ClusterPertain) ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) Cluster(com.sequenceiq.periscope.domain.Cluster) LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) LoadAlertConfiguration(com.sequenceiq.periscope.domain.LoadAlertConfiguration)

Example 3 with LoadAlert

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);
}
Also used : LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) Test(org.junit.Test)

Example 4 with LoadAlert

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;
}
Also used : LoadAlert(com.sequenceiq.periscope.domain.LoadAlert)

Example 5 with LoadAlert

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;
}
Also used : ClusterPertain(com.sequenceiq.periscope.domain.ClusterPertain) ScalingPolicy(com.sequenceiq.periscope.domain.ScalingPolicy) Cluster(com.sequenceiq.periscope.domain.Cluster) LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) LoadAlertConfiguration(com.sequenceiq.periscope.domain.LoadAlertConfiguration)

Aggregations

LoadAlert (com.sequenceiq.periscope.domain.LoadAlert)14 Cluster (com.sequenceiq.periscope.domain.Cluster)6 ScalingPolicy (com.sequenceiq.periscope.domain.ScalingPolicy)5 Test (org.junit.Test)5 ClusterPertain (com.sequenceiq.periscope.domain.ClusterPertain)3 LoadAlertConfiguration (com.sequenceiq.periscope.domain.LoadAlertConfiguration)3 List (java.util.List)2 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)1 AuthorizationResourceType (com.sequenceiq.authorization.resource.AuthorizationResourceType)1 AuthorizationEnvironmentCrnProvider (com.sequenceiq.authorization.service.AuthorizationEnvironmentCrnProvider)1 AuthorizationResourceCrnProvider (com.sequenceiq.authorization.service.AuthorizationResourceCrnProvider)1 WORKLOAD (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.WORKLOAD)1 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)1 AlertType (com.sequenceiq.periscope.api.model.AlertType)1 AutoscaleClusterState (com.sequenceiq.periscope.api.model.AutoscaleClusterState)1 LoadAlertRequest (com.sequenceiq.periscope.api.model.LoadAlertRequest)1 LoadAlertResponse (com.sequenceiq.periscope.api.model.LoadAlertResponse)1 ScalingPolicyRequest (com.sequenceiq.periscope.api.model.ScalingPolicyRequest)1 ScalingStatus (com.sequenceiq.periscope.api.model.ScalingStatus)1 StateJson (com.sequenceiq.periscope.api.model.StateJson)1