use of com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException in project cloudbreak by hortonworks.
the class StackUpscaleService method upscale.
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, UpscaleStackRequest<UpscaleStackResult> request, CloudConnector<?> connector) throws QuotaExceededException {
CloudStack cloudStack = request.getCloudStack();
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = request.getAdjustmentWithThreshold();
try {
return connector.resources().upscale(ac, cloudStack, request.getResourceList(), adjustmentTypeWithThreshold);
} catch (QuotaExceededException quotaExceededException) {
return handleQuotaExceptionAndRetryUpscale(request, connector, ac, cloudStack, adjustmentTypeWithThreshold, quotaExceededException);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testBestEffortButFail.
@Test
public void testBestEffortButFail() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 36, 40, "quota error", new Exception()));
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.BEST_EFFORT, 0L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
Assertions.assertThrows(CloudConnectorException.class, () -> stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector));
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(1)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
}
use of com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testBestEffort.
@Test
public void testBestEffort() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 20, 40, "quota error", new Exception())).thenReturn(Collections.emptyList());
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.BEST_EFFORT, 0L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector);
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(2)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
List<CloudStack> cloudStacks = cloudStackArgumentCaptor.getAllValues();
List<CloudInstance> cloudInstances = cloudStacks.get(1).getGroups().stream().flatMap(group -> group.getInstances().stream()).collect(Collectors.toList());
List<CloudInstance> cloudInstancesWithoutInstanceId = cloudInstances.stream().filter(cloudInstance -> cloudInstance.getInstanceId() == null).collect(Collectors.toList());
assertEquals(4, cloudInstances.size());
assertEquals(2, cloudInstancesWithoutInstanceId.size());
}
use of com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testExactWithProvisionableCount.
@Test
public void testExactWithProvisionableCount() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 20, 40, "quota error", new Exception())).thenReturn(Collections.emptyList());
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 2L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector);
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(2)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
List<CloudStack> cloudStacks = cloudStackArgumentCaptor.getAllValues();
List<CloudInstance> cloudInstances = cloudStacks.get(1).getGroups().stream().flatMap(group -> group.getInstances().stream()).collect(Collectors.toList());
List<CloudInstance> cloudInstancesWithoutInstanceId = cloudInstances.stream().filter(cloudInstance -> cloudInstance.getInstanceId() == null).collect(Collectors.toList());
assertEquals(4, cloudInstances.size());
assertEquals(2, cloudInstancesWithoutInstanceId.size());
}
use of com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException in project cloudbreak by hortonworks.
the class StackUpscaleServiceTest method testPercentageButFailBecauseHigherThanProvisionable.
@Test
public void testPercentageButFailBecauseHigherThanProvisionable() throws QuotaExceededException {
CloudConnector connector = mock(CloudConnector.class);
ResourceConnector resourceConnector = mock(ResourceConnector.class);
when(connector.resources()).thenReturn(resourceConnector);
when(resourceConnector.upscale(any(), any(), any(), any())).thenThrow(new QuotaExceededException(40, 20, 40, "quota error", new Exception()));
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.PERCENTAGE, 60L);
List<Group> groups = new ArrayList<>();
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker1.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute1.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet-1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty(), null, emptyMap()));
CloudStack cloudStack = new CloudStack(groups, mock(Network.class), mock(Image.class), Collections.emptyMap(), Collections.emptyMap(), "template", mock(InstanceAuthentication.class), "username", "publickey", mock(SpiFileSystem.class));
UpscaleStackRequest<UpscaleStackResult> upscaleStackRequest = new UpscaleStackRequest<>(mock(CloudContext.class), mock(CloudCredential.class), cloudStack, new ArrayList<>(), adjustmentTypeWithThreshold);
Assertions.assertThrows(CloudConnectorException.class, () -> stackUpscaleService.upscale(mock(AuthenticatedContext.class), upscaleStackRequest, connector));
verify(flowMessageService, times(1)).fireEventAndLog(upscaleStackRequest.getResourceId(), UPDATE_IN_PROGRESS.name(), STACK_UPSCALE_QUOTA_ISSUE, "quota error");
ArgumentCaptor<CloudStack> cloudStackArgumentCaptor = ArgumentCaptor.forClass(CloudStack.class);
verify(resourceConnector, times(1)).upscale(any(), cloudStackArgumentCaptor.capture(), any(), eq(adjustmentTypeWithThreshold));
}
Aggregations