Search in sources :

Example 1 with ResourceContextBuilder

use of com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder in project cloudbreak by hortonworks.

the class GcpResourceConnectorTest method testUpscaleWhenEverythingIsFine.

@Test
public void testUpscaleWhenEverythingIsFine() throws QuotaExceededException {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudStack cloudStack = mock(CloudStack.class);
    Network network = mock(Network.class);
    CloudContext cloudContext = mock(CloudContext.class);
    ResourceBuilderContext resourceBuilderContext = mock(ResourceBuilderContext.class);
    ResourceContextBuilder resourceContextBuilder = mock(ResourceContextBuilder.class);
    List<CloudResource> cloudResourceList = List.of(cloudResource("test-5", GCP_ATTACHED_DISKSET));
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudStack.getNetwork()).thenReturn(network);
    when(cloudContext.getPlatform()).thenReturn(platform("GCP"));
    when(cloudContext.getVariant()).thenReturn(GcpConstants.GCP_VARIANT);
    when(contextBuilders.get(any(Platform.class))).thenReturn(resourceContextBuilder);
    when(resourceContextBuilder.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), anyList(), anyBoolean())).thenReturn(resourceBuilderContext);
    when(networkResourceService.getNetworkResources(any(Variant.class), anyList())).thenReturn(new ArrayList<>());
    doNothing().when(resourceBuilderContext).addNetworkResources(anyCollection());
    when(groupResourceService.getGroupResources(any(Variant.class), anyCollection())).thenReturn(List.of(cloudResource("test-1", GCP_INSTANCE)));
    Group master = group("master");
    master.getInstances().get(0).putParameter(CloudInstance.FQDN, "fqdn");
    when(cloudStack.getGroups()).thenReturn(List.of(master));
    doNothing().when(resourceBuilderContext).addComputeResources(anyLong(), anyList());
    when(computeResourceService.buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any())).thenReturn(List.of());
    underTest.upscale(authenticatedContext, cloudStack, cloudResourceList, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
    verify(contextBuilders, times(1)).get(any(Platform.class));
    verify(networkResourceService, times(1)).getNetworkResources(any(Variant.class), anyList());
    verify(groupResourceService, times(1)).getGroupResources(any(Variant.class), anyList());
    verify(resourceBuilderContext, times(1)).addComputeResources(anyLong(), anyList());
    verify(computeResourceService, times(1)).buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ResourceContextBuilder(com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceContextBuilder

use of com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder in project cloudbreak by hortonworks.

the class GcpResourceConnectorTest method testLaunchLoadBalancersWhenEverythingIsFine.

@Test
public void testLaunchLoadBalancersWhenEverythingIsFine() throws Exception {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudStack cloudStack = mock(CloudStack.class);
    PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
    Network network = mock(Network.class);
    CloudContext cloudContext = mock(CloudContext.class);
    ResourceBuilderContext resourceBuilderContext = mock(ResourceBuilderContext.class);
    ResourceContextBuilder resourceContextBuilder = mock(ResourceContextBuilder.class);
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudStack.getNetwork()).thenReturn(network);
    when(cloudContext.getPlatform()).thenReturn(platform("GCP"));
    when(contextBuilders.get(any(Platform.class))).thenReturn(resourceContextBuilder);
    when(resourceContextBuilder.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), anyList(), anyBoolean())).thenReturn(resourceBuilderContext);
    when(loadBalancerResourceService.buildResources(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class))).thenReturn(List.of());
    underTest.launchLoadBalancers(authenticatedContext, cloudStack, persistenceNotifier);
    verify(contextBuilders, times(1)).get(any(Platform.class));
    verify(loadBalancerResourceService, times(1)).buildResources(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class));
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ResourceContextBuilder(com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.jupiter.api.Test)

Aggregations

AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)2 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 ResourceContextBuilder (com.sequenceiq.cloudbreak.cloud.template.ResourceContextBuilder)2 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)2 Test (org.junit.jupiter.api.Test)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 Variant (com.sequenceiq.cloudbreak.cloud.model.Variant)1 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)1 AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)1