Search in sources :

Example 11 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AzureResourceConnectorTest method testWhenTemplateDeploymentDoesNotExistThenComputeResourceServiceBuildsTheResources.

@Test
public void testWhenTemplateDeploymentDoesNotExistThenComputeResourceServiceBuildsTheResources() {
    when(client.templateDeploymentExists(RESOURCE_GROUP_NAME, STACK_NAME)).thenReturn(false);
    when(client.createTemplateDeployment(any(), any(), any(), any())).thenReturn(deployment);
    when(azureImageFormatValidator.isMarketplaceImageFormat(any())).thenReturn(false);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(ADJUSTMENT_TYPE, THRESHOLD);
    underTest.launch(ac, stack, notifier, adjustmentTypeWithThreshold);
    verify(azureComputeResourceService, times(1)).buildComputeResourcesForLaunch(eq(ac), eq(stack), eq(adjustmentTypeWithThreshold), eq(instances), any());
    verify(azureCloudResourceService, times(1)).getInstanceCloudResources(STACK_NAME, instances, groups, RESOURCE_GROUP_NAME);
    verify(azureUtils, times(1)).getCustomNetworkId(network);
    verify(azureUtils, times(1)).getCustomSubnetIds(network);
    verify(azureMarketplaceImageProviderService, times(0)).get(imageModel);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Test(org.junit.Test)

Example 12 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AzureResourceConnectorTest method testWhenTemplateDeploymentExistsAndInProgressThenComputeResourceServiceBuildsTheResources.

@Test
public void testWhenTemplateDeploymentExistsAndInProgressThenComputeResourceServiceBuildsTheResources() {
    when(client.templateDeploymentExists(RESOURCE_GROUP_NAME, STACK_NAME)).thenReturn(true);
    when(client.getTemplateDeployment(RESOURCE_GROUP_NAME, STACK_NAME)).thenReturn(deployment);
    when(client.getTemplateDeploymentStatus(RESOURCE_GROUP_NAME, STACK_NAME)).thenReturn(ResourceStatus.IN_PROGRESS);
    when(azureImageFormatValidator.isMarketplaceImageFormat(imageModel)).thenReturn(false);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(ADJUSTMENT_TYPE, THRESHOLD);
    underTest.launch(ac, stack, notifier, adjustmentTypeWithThreshold);
    verify(azureComputeResourceService, times(1)).buildComputeResourcesForLaunch(any(AuthenticatedContext.class), any(CloudStack.class), eq(adjustmentTypeWithThreshold), any(), any());
    verify(azureCloudResourceService, times(1)).getInstanceCloudResources(STACK_NAME, instances, groups, RESOURCE_GROUP_NAME);
    verify(azureUtils, times(1)).getCustomNetworkId(network);
    verify(client, never()).createTemplateDeployment(any(), any(), any(), any());
    verify(client, times(2)).getTemplateDeployment(any(), any());
    verify(azureMarketplaceImageProviderService, times(0)).get(imageModel);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 13 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AzureResourceConnectorTest method testWhenMarketplaceImageThenTemplateBuilderUsesMarketplaceImage.

@Test
public void testWhenMarketplaceImageThenTemplateBuilderUsesMarketplaceImage() {
    when(client.templateDeploymentExists(RESOURCE_GROUP_NAME, STACK_NAME)).thenReturn(false);
    when(client.createTemplateDeployment(any(), any(), any(), any())).thenReturn(deployment);
    when(azureImageFormatValidator.isMarketplaceImageFormat(any())).thenReturn(true);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(ADJUSTMENT_TYPE, THRESHOLD);
    underTest.launch(ac, stack, notifier, adjustmentTypeWithThreshold);
    verify(azureMarketplaceImageProviderService, times(1)).get(imageModel);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Test(org.junit.Test)

Example 14 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class MockResourceConnector method upscale.

@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources, AdjustmentTypeWithThreshold adjustmentTypeWithThreshold) {
    CloudContext cloudContext = authenticatedContext.getCloudContext();
    List<Group> scaledGroups = cloudResourceHelper.getScaledGroups(stack);
    List<Group> groups = scaledGroups.stream().map(g -> {
        List<CloudInstance> newInstances = g.getInstances().stream().filter(i -> i.getTemplate().getStatus() == InstanceStatus.CREATE_REQUESTED).collect(Collectors.toList());
        return new Group(g.getName(), g.getType(), newInstances, g.getSecurity(), g.getReferenceInstanceConfiguration(), g.getInstanceAuthentication(), g.getLoginUserName(), g.getPublicKey(), g.getRootVolumeSize(), g.getIdentity(), g.getNetwork(), g.getTags());
    }).collect(Collectors.toList());
    List<CloudVmInstanceStatus> resized = resize(authenticatedContext, groups);
    return generateResources(cloudContext, resized);
}
Also used : Arrays(java.util.Arrays) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CREATED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) MediaType(javax.ws.rs.core.MediaType) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Service(org.springframework.stereotype.Service) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) CloudResourceHelper(com.sequenceiq.cloudbreak.cloud.transform.CloudResourceHelper) ResourceType(com.sequenceiq.common.api.type.ResourceType) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DELETED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED) TemplatingNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.TemplatingNotSupportedException) UUID(java.util.UUID) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Response(javax.ws.rs.core.Response) Group(com.sequenceiq.cloudbreak.cloud.model.Group) ResourcePersisted(com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Example 15 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class YarnResourceConnectorTest method testLaunchWithStackDefaultParameters.

@Test
public void testLaunchWithStackDefaultParameters() throws Exception {
    ArgumentCaptor<CreateApplicationRequest> createRequestCaptor = ArgumentCaptor.forClass(CreateApplicationRequest.class);
    ArgumentCaptor<ApplicationDetailRequest> requestCaptor = ArgumentCaptor.forClass(ApplicationDetailRequest.class);
    setUpHappyPath(createRequestCaptor, requestCaptor);
    when(applicationNameUtilMock.createApplicationName(authenticatedContextMock)).thenReturn("name-1-horton");
    when(yarnApplicationCreationService.initializeRequest(any(), any())).thenReturn(createInitialApplicationRequest("name-1-horton"));
    underTest.launch(authenticatedContextMock, stackMock, persistenceNotifierMock, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
    verify(yarnApplicationCreationService).createApplication(any(), createRequestCaptor.capture());
    CreateApplicationRequest capturedCreateRequest = createRequestCaptor.getValue();
    assertEquals("name-1-horton", capturedCreateRequest.getName());
}
Also used : CreateApplicationRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.CreateApplicationRequest) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Test(org.junit.Test)

Aggregations

AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)41 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)20 Group (com.sequenceiq.cloudbreak.cloud.model.Group)20 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)15 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)12 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 List (java.util.List)12 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 QuotaExceededException (com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException)9 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)9 AdjustmentType (com.sequenceiq.common.api.type.AdjustmentType)9 Inject (javax.inject.Inject)9