Search in sources :

Example 41 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class StackV4RequestToGatewayConverter method convert.

public Gateway convert(StackV4Request source) {
    Gateway gateway = new Gateway();
    GatewayV4Request gatewayJson = source.getCluster().getGateway();
    ValidationResult validationResult = gatewayJsonValidator.validate(gatewayJson);
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
    convertUtil.setBasicProperties(gatewayJson, gateway);
    convertUtil.setTopologies(gatewayJson, gateway);
    convertUtil.setGatewayPathAndSsoProvider(gatewayJson, gateway);
    return gateway;
}
Also used : GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 42 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class GatewayTopologyV4RequestValidatorTest method testWithInvalidKnoxServiceAndNoTopologyName.

@Test
public void testWithInvalidKnoxServiceAndNoTopologyName() {
    String invalidService = "INVALID_SERVICE";
    GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
    gatewayTopologyJson.setExposedServices(Collections.singletonList(invalidService));
    when(exposedServiceListValidator.validate(anyList())).thenReturn(new ValidationResultBuilder().error(invalidService).build());
    ValidationResult result = underTest.validate(gatewayTopologyJson);
    assertEquals(State.ERROR, result.getState());
    assertEquals(2L, result.getErrors().size());
    assertTrue(result.getErrors().get(0).contains(invalidService));
    assertTrue(result.getErrors().get(1).contains("topologyName must be set in gateway topology."));
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 43 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class GatewayV4RequestValidatorTest method testValidationWithMissingTopology.

@Test
public void testValidationWithMissingTopology() {
    GatewayV4Request gatewayJson = new GatewayV4Request();
    ValidationResult result = underTest.validate(gatewayJson);
    assertEquals(State.ERROR, result.getState());
    assertTrue(result.getFormattedErrors().contains("No topology is defined in gateway request."));
}
Also used : GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 44 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class HostMetadataSetupTest method testSetupNewHostMetadataWithMultiNonGatewayInstances.

@Test
@DisplayName("when multiple non-gateway instances are repaired and scaled we shouldn't make any changes")
public void testSetupNewHostMetadataWithMultiNonGatewayInstances() throws CloudbreakException, CloudbreakOrchestratorException {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = createInstanceMetadata("id1", InstanceMetadataType.CORE, 1L, "10.0.0.1", "host1", false);
    InstanceMetaData im2 = createInstanceMetadata("id2", InstanceMetadataType.CORE, 2L, "10.0.0.2", "host2", false);
    when(instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(STACK_ID)).thenReturn(Set.of(im1, im2));
    when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
    when(hostOrchestrator.getMembers(any(), any())).thenReturn(Map.of("10.0.0.1", "host1", "10.0.0.2", "host2"));
    hostMetadataSetup.setupNewHostMetadata(STACK_ID, List.of("10.0.0.1", "10.0.0.2"));
    verify(instanceMetaDataService, times(0)).getLastTerminatedPrimaryGatewayInstanceMetadata(STACK_ID);
    verify(instanceMetaDataService, times(1)).saveAll(instanceMetadataCaptor.capture());
    Set<InstanceMetaData> actualIm = instanceMetadataCaptor.getValue();
    InstanceMetaData expectedIm1 = createInstanceMetadata("id1", InstanceMetadataType.CORE, 1L, "10.0.0.1", "host1", false);
    InstanceMetaData expectedIm2 = createInstanceMetadata("id2", InstanceMetadataType.CORE, 2L, "10.0.0.2", "host2", false);
    assertMetadataEquals(expectedIm1, actualIm.stream().filter(im -> im.getPrivateId() == 1L).findFirst().get());
    assertMetadataEquals(expectedIm2, actualIm.stream().filter(im -> im.getPrivateId() == 2L).findFirst().get());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Captor(org.mockito.Captor) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMocks(org.mockito.InjectMocks) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Mockito.verify(org.mockito.Mockito.verify) DisplayName(org.junit.jupiter.api.DisplayName) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Test(org.junit.jupiter.api.Test) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Assertions(org.junit.jupiter.api.Assertions) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Mockito.mock(org.mockito.Mockito.mock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 45 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class StackDecoratorTest method setUp.

@Before
public void setUp() {
    String credentialName = "credentialName";
    MockitoAnnotations.initMocks(this);
    subject = new Stack();
    subject.setEnvironmentCrn("envCrn");
    Set<InstanceGroup> instanceGroups = createInstanceGroups(GATEWAY);
    subject.setInstanceGroups(instanceGroups);
    Cluster cluster = getCluster(instanceGroups);
    subject.setCluster(cluster);
    subject.setCloudPlatform("AZURE");
    subject.setParameters(new HashMap<>());
    when(cloudParameterCache.getPlatformParameters()).thenReturn(platformParametersMap);
    when(platformParametersMap.get(any(Platform.class))).thenReturn(pps);
    when(pps.specialParameters()).thenReturn(specialParameters);
    when(specialParameters.getSpecialParameters()).thenReturn(specialParametersMap);
    when(specialParametersMap.get(anyString())).thenReturn(false);
    when(cloudParameterService.getOrchestrators()).thenReturn(platformOrchestrators);
    when(platformOrchestrators.getDefaults()).thenReturn(defaultOrchestrator);
    when(defaultOrchestrator.get(any(Platform.class))).thenReturn(orchestrator);
    when(instanceGroupToInstanceGroupParameterRequestConverter.convert(any(InstanceGroup.class))).thenReturn(instanceGroupParameterRequest);
    when(request.getCluster()).thenReturn(clusterRequest);
    when(environmentSettingsRequest.getCredentialName()).thenReturn(credentialName);
    when(sharedServiceValidator.checkSharedServiceStackRequirements(any(StackV4Request.class), any(Workspace.class))).thenReturn(validationResult);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    CompactRegionResponse crr = new CompactRegionResponse();
    crr.setNames(Lists.newArrayList("region"));
    environmentResponse.setRegions(crr);
    EnvironmentNetworkResponse enr = new EnvironmentNetworkResponse();
    Map<String, CloudSubnet> subnetmetas = Maps.newHashMap("subnet", new CloudSubnet("id", "name", "availabilityzone", "cidr"));
    enr.setSubnetMetas(subnetmetas);
    environmentResponse.setNetwork(enr);
    environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName("resource-group").build()).build());
    when(request.getCloudPlatform()).thenReturn(CloudPlatform.AZURE);
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    Credential credential = Credential.builder().cloudPlatform(CloudPlatform.MOCK.name()).build();
    when(credentialClientService.getByCrn(anyString())).thenReturn(credential);
    when(credentialClientService.getByName(anyString())).thenReturn(credential);
    when(credentialConverter.convert(credentialResponse)).thenReturn(credential);
    ExtendedCloudCredential extendedCloudCredential = mock(ExtendedCloudCredential.class);
    when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCloudCredential);
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Before(org.junit.Before)

Aggregations

Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)20 Test (org.junit.Test)18 GatewayV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)16 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)15 Set (java.util.Set)15 Map (java.util.Map)14 List (java.util.List)13 Test (org.junit.jupiter.api.Test)12 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)10 Json (com.sequenceiq.cloudbreak.common.json.Json)9 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Optional (java.util.Optional)9 Collectors (java.util.stream.Collectors)9 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)8 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)8 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)8 HashSet (java.util.HashSet)8 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)7 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)7