use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class TemplateDecorator method resolveVolumeParameterConfig.
private VolumeParameterConfig resolveVolumeParameterConfig(Template template, VolumeTemplate volumeTemplate, PlatformDisks platformDisks, CloudVmTypes vmTypesV2, String locationString) {
Platform platform = Platform.platform(template.cloudPlatform());
Map<String, VolumeParameterType> map = platformDisks.getDiskMappings().get(platform);
VolumeParameterType volumeParameterType = map.get(volumeTemplate.getVolumeType());
if (volumeParameterType == null) {
throw new CloudbreakServiceException("Cannot find the volume type: " + volumeTemplate.getVolumeType() + ". Supported types: " + String.join(", ", map.keySet()));
}
VmType vmType = vmTypesV2.getCloudVmResponses().getOrDefault(locationString, Collections.emptySet()).stream().filter(curr -> curr.value().equals(template.getInstanceType())).findFirst().get();
return vmType.getVolumeParameterbyVolumeParameterType(volumeParameterType);
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AccountTagClientService method list.
public Map<String, String> list() {
try {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
AccountTagResponses list = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> accountTagEndpoint.listInAccount(accountId));
return list.getResponses().stream().collect(Collectors.toMap(AccountTagResponse::getKey, AccountTagResponse::getValue));
} catch (WebApplicationException | ProcessingException | IllegalStateException e) {
String message = String.format("Failed to GET AccountTags with account id, due to: '%s' ", e.getMessage());
LOGGER.error(message, e);
throw new CloudbreakServiceException(message, e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class RedbeamsDbServerConfigurer method createNewRdsConfig.
/**
* Creates an RDSConfig object for a specific database.
*
* @param stack stack for naming purposes
* @param cluster cluster to associate database with
* @param dbName database name
* @param dbUser database user
* @param type database type
* @return RDSConfig object for database
*/
public RDSConfig createNewRdsConfig(Stack stack, Cluster cluster, String dbName, String dbUser, DatabaseType type) {
DatabaseServerV4Response resp = getDatabaseServer(cluster.getDatabaseServerCrn());
LOGGER.info("Using redbeams for remote database configuration: {}", resp.toString());
if (Objects.nonNull(resp.getStatus()) && !resp.getStatus().isAvailable()) {
String message = String.format("Redbeams database server is not available (%s) with message: %s", resp.getStatus(), resp.getStatusReason());
LOGGER.warn(message);
throw new CloudbreakServiceException(message);
}
RDSConfig rdsConfig = new RDSConfig();
rdsConfig.setConnectionURL(dbCommon.getJdbcConnectionUrl(resp.getDatabaseVendor(), resp.getHost(), resp.getPort(), Optional.of(dbName)));
rdsConfig.setSslMode(getSslMode(resp));
rdsConfig.setConnectionUserName(dbUsernameConverterService.toConnectionUsername(resp.getHost(), dbUser));
rdsConfig.setConnectionPassword(PasswordUtil.generatePassword());
rdsConfig.setConnectionDriver(resp.getConnectionDriver());
rdsConfig.setDatabaseEngine(DatabaseVendor.fromValue(resp.getDatabaseVendor()));
rdsConfig.setStatus(ResourceStatus.DEFAULT);
rdsConfig.setName(type.name() + '_' + stack.getName() + stack.getId());
rdsConfig.setType(type.name());
rdsConfig.setStatus(ResourceStatus.DEFAULT);
rdsConfig.setCreationDate(new Date().getTime());
rdsConfig.setClusters(Collections.singleton(cluster));
LOGGER.info("Created RDS config {} for database type {} with connection URL {}, connection username {}", rdsConfig.getName(), type, rdsConfig.getConnectionURL(), rdsConfig.getConnectionUserName());
return rdsConfig;
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackImageService method replaceStackImageComponent.
private void replaceStackImageComponent(Stack stack, StatedImage targetImage) {
try {
Image newImage = getImageModelFromStatedImage(stack, componentConfigProviderService.getImage(stack.getId()), targetImage);
Component imageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(newImage), stack);
componentConfigProviderService.replaceImageComponentWithNew(imageComponent);
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info("Could not find image", e);
throw new CloudbreakServiceException("Could not find image", e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, Map<String, Integer> hostGroupsWithInstanceCountToCreate, Map<String, Set<String>> hostGroupWithHostnames, boolean save, boolean repair, NetworkScaleDetails networkScaleDetails) {
LOGGER.info("Get updated stack with instance count ({}) and hostnames: {} and save: ({})", hostGroupsWithInstanceCountToCreate, hostGroupWithHostnames, save);
DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack.getEnvironmentCrn());
Map<String, String> subnetAzPairs = multiAzCalculatorService.prepareSubnetAzMap(environment);
String stackSubnetId = getStackSubnetIdIfExists(stack);
String stackAz = stackSubnetId == null ? null : subnetAzPairs.get(stackSubnetId);
long privateId = getFirstValidPrivateId(stack.getInstanceGroupsAsList());
for (Map.Entry<String, Integer> hostGroupWithInstanceCount : hostGroupsWithInstanceCountToCreate.entrySet()) {
String hostGroup = hostGroupWithInstanceCount.getKey();
Integer instanceToCreate = hostGroupWithInstanceCount.getValue();
Iterator<String> hostNameIterator = getHostNameIterator(hostGroupWithHostnames.get(hostGroup));
for (int i = 0; i < instanceToCreate; i++) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), hostGroup);
if (instanceGroup != null) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(privateId++);
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformVariant());
if (hostNameIterator.hasNext()) {
String hostName = hostNameIterator.next();
repository.findHostInStack(stack.getId(), hostName).ifPresent(existingHost -> {
throw new CloudbreakServiceException("There is an existing host with the same FQDN. It can happen if you retried a failed repair. " + "Please start the repairing process again instead of retry.");
});
LOGGER.info("We have hostname to be allocated: {}, set it to this instanceMetadata: {}", hostName, instanceMetaData);
instanceMetaData.setDiscoveryFQDN(hostName);
subnetAzPairs = getSubnetAzPairsFilteredByHostNameIfRepair(environment, stack, repair, instanceGroup.getGroupName(), hostName);
}
Map<String, String> filteredSubnetsByLeastUsedAz = networkScaleDetails == null ? multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzPairs) : subnetAzPairs;
prepareInstanceMetaDataSubnetAndAvailabilityZoneAndRackId(instanceGroup, instanceMetaData, filteredSubnetsByLeastUsedAz, stackSubnetId, stackAz, networkScaleDetails);
if (save) {
repository.save(instanceMetaData);
}
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
Aggregations