Search in sources :

Example 21 with CloudbreakServiceException

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);
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType)

Example 22 with CloudbreakServiceException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) AccountTagResponses(com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponses) ProcessingException(javax.ws.rs.ProcessingException)

Example 23 with CloudbreakServiceException

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;
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Date(java.util.Date)

Example 24 with CloudbreakServiceException

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);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 25 with CloudbreakServiceException

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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Map(java.util.Map) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12