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());
}
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());
}
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");
}
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);
}
}
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);
}
Aggregations