Search in sources :

Example 1 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class NetworkServiceTest method testAzureMultipleNetworkWithSameId.

@Test
public void testAzureMultipleNetworkWithSameId() {
    Stack stack = new Stack();
    stack.setCloudPlatform(PLATFORM);
    stack.setRegion(REGION);
    stack.setPlatformvariant(PLATFORM);
    Credential credential = new Credential(PLATFORM, "", "", "", "acc");
    ExtendedCloudCredential extendedCred = new ExtendedCloudCredential(new CloudCredential(), PLATFORM, "", "", "", new ArrayList<>());
    CloudSubnet subnet1 = new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.1.0.0/24");
    CloudSubnet subnet2 = new CloudSubnet(SUBNET_2, SUBNET_2, "", "10.1.1.0/24");
    CloudSubnet subnet3 = new CloudSubnet("indifferent", "indifferent", "", "10.1.2.0/24");
    CloudNetwork cloudNetwork1 = new CloudNetwork("/rg1/" + NETWORK_ID, "/rg1/" + NETWORK_ID, Set.of(subnet1, subnet2, subnet3), Map.of());
    CloudNetwork cloudNetwork2 = new CloudNetwork("/rg2/" + NETWORK_ID, "/rg2/" + NETWORK_ID, Set.of(new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.2.0.0/24"), new CloudSubnet("test", "test")), Map.of());
    Map<String, Set<CloudNetwork>> cloudNets = Map.of(REGION, Set.of(cloudNetwork1, cloudNetwork2));
    CloudNetworks cloudNetworks = new CloudNetworks(cloudNets);
    when(credentialService.getCredentialByEnvCrn(ENV_CRN)).thenReturn(credential);
    when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCred);
    when(cloudParameterService.getCloudNetworks(eq(extendedCred), eq(REGION), eq(PLATFORM), any())).thenReturn(cloudNetworks);
    when(networkFilterProviderMap.get(any())).thenReturn(null);
    Multimap<String, String> filteredSubnetWithCidr = underTest.getFilteredSubnetWithCidr(ENV_CRN, stack, NETWORK_ID, List.of(SUBNET_1, SUBNET_2));
    assertEquals(3, filteredSubnetWithCidr.size());
    assertEquals(2, filteredSubnetWithCidr.get(subnet1.getId()).size());
    assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains(subnet1.getCidr()));
    assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains("10.2.0.0/24"));
    assertEquals(1, filteredSubnetWithCidr.get(subnet2.getId()).size());
    assertEquals(subnet2.getCidr(), filteredSubnetWithCidr.get(subnet2.getId()).stream().findFirst().get());
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Set(java.util.Set) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class FreeIpaRecommendationServiceTest method testValidateCustomInstanceTypeWhenEntitlementIsNotEnabled.

@Test
public void testValidateCustomInstanceTypeWhenEntitlementIsNotEnabled() {
    when(defaultInstanceTypeProvider.getForPlatform(eq("AWS"))).thenReturn("medium");
    when(entitlementService.isFreeIpaSelectInstanceTypeEnabled(anyString())).thenReturn(Boolean.FALSE);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateCustomInstanceType(createStack("large"), new Credential("AWS", "Cred", null, "crn", "account")));
    assertEquals("Custom instance type for FreeIPA is not enabled!", badRequestException.getMessage());
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 3 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class FreeIpaRecommendationServiceTest method testGetRecommendation.

@Test
public void testGetRecommendation() {
    when(credentialService.getCredentialByCredCrn(anyString())).thenReturn(new Credential("AWS", "", "", "", ""));
    when(cloudParameterService.getVmTypesV2(any(), eq("eu-central-1"), eq("AWS"), eq(CdpResourceType.DEFAULT), any())).thenReturn(initCloudVmTypes());
    when(defaultInstanceTypeProvider.getForPlatform(eq("AWS"))).thenReturn("medium");
    FreeIpaRecommendationResponse recommendation = underTest.getRecommendation("cred", "eu-central-1", null);
    assertEquals("medium", recommendation.getDefaultInstanceType());
    Set<VmTypeResponse> vmTypes = recommendation.getVmTypes();
    assertEquals(2, vmTypes.size());
    assertThat(vmTypes.stream().map(VmTypeResponse::getValue).collect(Collectors.toSet())).containsExactly("large", "medium");
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse) Test(org.junit.jupiter.api.Test)

Example 4 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class UserDataService method createUserData.

private void createUserData(Stack stack, Supplier<CcmConnectivityParameters> ccmParametersSupplier) {
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> platformParameterService.getPlatformParameters(stack, credential));
    SecurityConfig securityConfig = stack.getSecurityConfig();
    SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
    String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
    byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
    String sshUser = stack.getStackAuthentication().getLoginUserName();
    String cbCert = securityConfig.getClientCert();
    String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
    try {
        PlatformParameters platformParameters = platformParametersFuture.get();
        CcmConnectivityParameters ccmParameters = ccmParametersSupplier.get();
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        String userData = userDataBuilder.buildUserData(stack.getAccountId(), environment, Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
        imageService.decorateImageWithUserDataForStack(stack, userData);
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Failed to get Platform parameters", e);
        throw new GetCloudParameterException("Failed to get Platform parameters", e);
    }
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SaltSecurityConfig(com.sequenceiq.freeipa.entity.SaltSecurityConfig) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class AbstractStackStopAction method createFlowContext.

@Override
protected StackStopContext createFlowContext(FlowParameters flowParameters, StateContext<StackStopState, StackStopEvent> stateContext, P payload) {
    Long stackId = payload.getResourceId();
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    MDCBuilder.buildMdcContext(stack);
    List<InstanceMetaData> instances = new ArrayList<>(instanceMetaDataService.findNotTerminatedForStack(stackId));
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    return new StackStopContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) StackStopContext(com.sequenceiq.freeipa.flow.stack.stop.StackStopContext) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Credential (com.sequenceiq.freeipa.dto.Credential)17 Stack (com.sequenceiq.freeipa.entity.Stack)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 CredentialService (com.sequenceiq.freeipa.service.CredentialService)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)3 Location (com.sequenceiq.cloudbreak.cloud.model.Location)3 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 FreeIpaRecommendationResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse)3 VmTypeResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse)3 CredentialToCloudCredentialConverter (com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter)3 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)3