use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.
the class ImageService method create.
@Transactional(TxType.NEVER)
public void create(Stack stack, PlatformParameters params, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
try {
Platform platform = platform(stack.cloudPlatform());
String platformString = platform(stack.cloudPlatform()).value().toLowerCase();
String region = stack.getRegion();
SecurityConfig securityConfig = stack.getSecurityConfig();
String cbPrivKey = securityConfig.getCloudbreakSshPrivateKeyDecoded();
byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(cbPrivKey);
String sshUser = stack.getStackAuthentication().getLoginUserName();
String cbCert = securityConfig.getClientCertRaw();
Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(platform, cbSshKeyDer, sshUser, params, securityConfig.getSaltBootPassword(), cbCert);
StatedImage imgFromCatalog = determineImageFromCatalog(imageId, platformString, imageCatalog, blueprint);
LOGGER.info("Determined image from catalog: {}", imgFromCatalog);
String imageName = determineImageName(platformString, region, imgFromCatalog.getImage());
LOGGER.info("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
List<Component> components = getComponents(stack, userData, imgFromCatalog.getImage(), imageName, imgFromCatalog.getImageCatalogUrl(), imgFromCatalog.getImageCatalogName(), imgFromCatalog.getImage().getUuid());
componentConfigProvider.store(components);
} catch (JsonProcessingException e) {
throw new CloudbreakServiceException("Failed to create json", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.
the class MockPlatformResources method getDefaultRegion.
private Region getDefaultRegion() {
Map<Platform, Region> defaultRegionsMap = Maps.newHashMap();
if (isNoneEmpty(defaultRegions)) {
for (String entry : defaultRegions.split(",")) {
String[] keyValue = entry.split(":");
defaultRegionsMap.put(platform(keyValue[0]), Region.region(keyValue[1]));
}
Region platformRegion = defaultRegionsMap.get(platform(MockConstants.MOCK));
if (platformRegion != null && !isEmpty(platformRegion.value())) {
return getRegionByName(platformRegion.value());
}
}
return regions.keySet().iterator().next();
}
use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.
the class GetDiskTypesHandler method accept.
@Override
public void accept(Event<GetDiskTypesRequest> getDiskTypesRequestEvent) {
LOGGER.info("Received event: {}", getDiskTypesRequestEvent);
GetDiskTypesRequest request = getDiskTypesRequestEvent.getData();
try {
Map<Platform, Collection<DiskType>> platformDiskTypes = Maps.newHashMap();
Map<Platform, DiskType> defaultDiskTypes = Maps.newHashMap();
Map<Platform, Map<String, VolumeParameterType>> diskMappings = Maps.newHashMap();
Map<Platform, Map<DiskType, DisplayName>> diskDisplayNames = Maps.newHashMap();
for (Entry<Platform, Collection<Variant>> connector : cloudPlatformConnectors.getPlatformVariants().getPlatformToVariants().entrySet()) {
DiskTypes diskTypes = cloudPlatformConnectors.getDefault(connector.getKey()).parameters().diskTypes();
defaultDiskTypes.put(connector.getKey(), diskTypes.defaultType());
platformDiskTypes.put(connector.getKey(), diskTypes.types());
diskMappings.put(connector.getKey(), diskTypes.diskMapping());
diskDisplayNames.put(connector.getKey(), diskTypes.displayNames());
}
GetDiskTypesResult getDiskTypesResult = new GetDiskTypesResult(request, new PlatformDisks(platformDiskTypes, defaultDiskTypes, diskMappings, diskDisplayNames));
request.getResult().onNext(getDiskTypesResult);
LOGGER.info("Query platform disk types finished.");
} catch (RuntimeException e) {
request.getResult().onNext(new GetDiskTypesResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.
the class GetPlatformOrchestratorsHandler method accept.
@Override
public void accept(Event<GetPlatformOrchestratorsRequest> getPlatformOrchestratorsRequest) {
LOGGER.info("Received event: {}", getPlatformOrchestratorsRequest);
GetPlatformOrchestratorsRequest request = getPlatformOrchestratorsRequest.getData();
try {
Map<Platform, Collection<Orchestrator>> platformCollectionHashMap = Maps.newHashMap();
Map<Platform, Orchestrator> defaults = Maps.newHashMap();
for (Entry<Platform, Collection<Variant>> connector : cloudPlatformConnectors.getPlatformVariants().getPlatformToVariants().entrySet()) {
PlatformOrchestrator platformOrchestrator = cloudPlatformConnectors.getDefault(connector.getKey()).parameters().orchestratorParams();
platformCollectionHashMap.put(connector.getKey(), platformOrchestrator.types());
defaults.put(connector.getKey(), platformOrchestrator.defaultType());
}
GetPlatformOrchestratorsResult getPlatformOrchestratorsResult = new GetPlatformOrchestratorsResult(request, new PlatformOrchestrators(platformCollectionHashMap, defaults));
request.getResult().onNext(getPlatformOrchestratorsResult);
LOGGER.info("Query platform orchestrators types finished.");
} catch (RuntimeException e) {
request.getResult().onNext(new GetPlatformOrchestratorsResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.
the class StackRequestToStackConverter method getRegion.
private String getRegion(StackRequest source) {
boolean containerOrchestrator;
try {
containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
} catch (CloudbreakException ignored) {
throw new BadRequestException("Orchestrator not supported.");
}
if (OrchestratorConstants.YARN.equals(source.getOrchestrator().getType())) {
return OrchestratorConstants.YARN;
}
if (isEmpty(source.getRegion()) && !containerOrchestrator) {
Map<Platform, Region> regions = Maps.newHashMap();
if (isNoneEmpty(defaultRegions)) {
for (String entry : defaultRegions.split(",")) {
String[] keyValue = entry.split(":");
regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
}
Region platformRegion = regions.get(platform(source.getCloudPlatform()));
if (platformRegion == null || isEmpty(platformRegion.value())) {
throw new BadRequestException(String.format("No default region specified for: %s. Region cannot be empty.", source.getCloudPlatform()));
}
return platformRegion.value();
} else {
throw new BadRequestException("No default region is specified. Region cannot be empty.");
}
}
return source.getRegion();
}
Aggregations