Search in sources :

Example 41 with RDSConfig

use of com.sequenceiq.cloudbreak.domain.RDSConfig in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverter method convert.

protected <R extends ClusterResponse> R convert(Cluster source, Class<R> clazz) throws IllegalAccessException, InstantiationException {
    R clusterResponse = clazz.newInstance();
    clusterResponse.setId(source.getId());
    clusterResponse.setName(source.getName());
    clusterResponse.setStatus(source.getStatus());
    clusterResponse.setStatusReason(source.getStatusReason());
    if (source.getBlueprint() != null) {
        clusterResponse.setBlueprintId(source.getBlueprint().getId());
    }
    long uptime = stackUtil.getUptimeForCluster(source, source.isAvailable());
    int minutes = (int) ((uptime / (MILLIS_PER_SECOND * SECONDS_PER_MINUTE)) % SECONDS_PER_MINUTE);
    int hours = (int) (uptime / (MILLIS_PER_SECOND * SECONDS_PER_MINUTE * SECONDS_PER_MINUTE));
    clusterResponse.setUptime(uptime);
    clusterResponse.setHoursUp(hours);
    clusterResponse.setMinutesUp(minutes);
    Set<RDSConfig> rdsConfigs = source.getRdsConfigs();
    convertRdsIds(clusterResponse, rdsConfigs);
    if (source.getLdapConfig() != null) {
        clusterResponse.setLdapConfigId(source.getLdapConfig().getId());
    }
    if (source.getAttributes() != null) {
        clusterResponse.setAttributes(source.getAttributes().getMap());
    }
    String ambariIp = stackUtil.extractAmbariIp(source.getStack());
    clusterResponse.setAmbariServerIp(ambariIp);
    clusterResponse.setUserName(source.getUserName());
    clusterResponse.setExecutorType(source.getExecutorType());
    clusterResponse.setDescription(source.getDescription() == null ? "" : source.getDescription());
    clusterResponse.setExtendedBlueprintText(source.getExtendedBlueprintText() == null ? source.getBlueprint().getBlueprintText() : source.getExtendedBlueprintText());
    clusterResponse.setHostGroups(convertHostGroupsToJson(source.getHostGroups()));
    clusterResponse.setAmbariServerUrl(getAmbariServerUrl(source, ambariIp));
    clusterResponse.setServiceEndPoints(prepareServiceEndpointsMap(source, ambariIp));
    clusterResponse.setBlueprintInputs(convertBlueprintInputs(source.getBlueprintInputs()));
    clusterResponse.setConfigStrategy(source.getConfigStrategy());
    setExtendedBlueprintText(source, clusterResponse);
    clusterResponse.setLdapConfig(getConversionService().convert(source.getLdapConfig(), LdapConfigResponse.class));
    convertRdsConfigs(source, clusterResponse);
    clusterResponse.setBlueprint(getConversionService().convert(source.getBlueprint(), BlueprintResponse.class));
    convertKnox(source, clusterResponse);
    convertCustomQueue(source, clusterResponse);
    if (source.getBlueprintCustomProperties() != null) {
        clusterResponse.setBlueprintCustomProperties(jsonHelper.createJsonFromString(source.getBlueprintCustomProperties()));
    }
    convertContainerConfig(source, clusterResponse);
    convertComponentConfig(clusterResponse, source);
    clusterResponse.setCreationFinished(source.getCreationFinished());
    KerberosConfig kerberosConfig = source.getKerberosConfig();
    if (source.isSecure() && kerberosConfig != null) {
        clusterResponse.setSecure(source.isSecure());
        clusterResponse.setKerberosResponse(getConversionService().convert(source.getKerberosConfig(), KerberosResponse.class));
    }
    decorateResponseWithProxyConfig(source, clusterResponse);
    return clusterResponse;
}
Also used : KerberosResponse(com.sequenceiq.cloudbreak.api.model.KerberosResponse) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) LdapConfigResponse(com.sequenceiq.cloudbreak.api.model.ldap.LdapConfigResponse) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintResponse(com.sequenceiq.cloudbreak.api.model.BlueprintResponse)

Example 42 with RDSConfig

use of com.sequenceiq.cloudbreak.domain.RDSConfig in project cloudbreak by hortonworks.

the class RDSConfigRequestToRDSConfigConverter method convert.

@Override
public RDSConfig convert(RDSConfigRequest source) {
    RDSConfig rdsConfig = new RDSConfig();
    if (Strings.isNullOrEmpty(source.getName())) {
        rdsConfig.setName(missingResourceNameGenerator.generateName(APIResourceType.RDS_CONFIG));
    } else {
        rdsConfig.setName(source.getName());
    }
    rdsConfig.setConnectionURL(source.getConnectionURL());
    Optional<DatabaseVendor> databaseVendor = DatabaseVendor.getVendorByJdbcUrl(source.getConnectionURL());
    if (databaseVendor.isPresent()) {
        rdsConfig.setDatabaseEngine(databaseVendor.get().name());
        rdsConfig.setConnectionDriver(databaseVendor.get().connectionDriver());
    } else {
        throw new BadRequestException("Not a valid DatabaseVendor which was provided in the jdbc url.");
    }
    rdsConfig.setConnectionUserName(source.getConnectionUserName());
    rdsConfig.setConnectionPassword(source.getConnectionPassword());
    rdsConfig.setCreationDate(new Date().getTime());
    rdsConfig.setStatus(ResourceStatus.USER_MANAGED);
    rdsConfig.setType(source.getType());
    return rdsConfig;
}
Also used : DatabaseVendor(com.sequenceiq.cloudbreak.api.model.DatabaseVendor) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Date(java.util.Date)

Example 43 with RDSConfig

use of com.sequenceiq.cloudbreak.domain.RDSConfig in project cloudbreak by hortonworks.

the class ClusterDecorator method prepareRds.

private void prepareRds(Cluster subject, IdentityUser user, ClusterRequest request, Stack stack) {
    subject.setRdsConfigs(new HashSet<>());
    if (request.getRdsConfigIds() != null) {
        for (Long rdsConfigId : request.getRdsConfigIds()) {
            RDSConfig rdsConfig = rdsConfigService.get(rdsConfigId);
            subject.getRdsConfigs().add(rdsConfig);
        }
    }
    if (request.getRdsConfigJsons() != null) {
        for (RDSConfigRequest requestRdsConfig : request.getRdsConfigJsons()) {
            RDSConfig rdsConfig = conversionService.convert(requestRdsConfig, RDSConfig.class);
            rdsConfig.setPublicInAccount(stack.isPublicInAccount());
            rdsConfig = rdsConfigService.createIfNotExists(user, rdsConfig);
            subject.getRdsConfigs().add(rdsConfig);
        }
    }
    Optional.of(request.getRdsConfigNames()).ifPresent(confs -> confs.forEach(confName -> subject.getRdsConfigs().add(rdsConfigService.getPublicRdsConfig(confName, user))));
    if (request.getAmbariDatabaseDetails() != null) {
        RDSConfig rdsConfig = ambariDatabaseMapper.mapAmbariDatabaseDetailsJsonToRdsConfig(request.getAmbariDatabaseDetails(), subject, stack, stack.isPublicInAccount());
        subject.getRdsConfigs().add(rdsConfigService.createIfNotExists(user, rdsConfig));
    }
    ambariConfigurationService.createDefaultRdsConfigIfNeeded(stack, subject).ifPresent(rdsConfig -> subject.getRdsConfigs().add(rdsConfig));
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) RdsType(com.sequenceiq.cloudbreak.api.model.rds.RdsType) LoggerFactory(org.slf4j.LoggerFactory) RDSConfigRequest(com.sequenceiq.cloudbreak.api.model.rds.RDSConfigRequest) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) StringUtils(org.apache.commons.lang3.StringUtils) AmbariConfigurationService(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariConfigurationService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Map(java.util.Map) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Json(com.sequenceiq.cloudbreak.domain.json.Json) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) BlueprintParameter(com.sequenceiq.cloudbreak.domain.BlueprintParameter) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) RdsConnectionValidator(com.sequenceiq.cloudbreak.controller.validation.rds.RdsConnectionValidator) Logger(org.slf4j.Logger) LdapConfigValidator(com.sequenceiq.cloudbreak.controller.validation.ldapconfig.LdapConfigValidator) ClusterRequest(com.sequenceiq.cloudbreak.api.model.ClusterRequest) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) LdapConfigRequest(com.sequenceiq.cloudbreak.api.model.ldap.LdapConfigRequest) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) IOException(java.io.IOException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) ConnectedClusterRequest(com.sequenceiq.cloudbreak.api.model.ConnectedClusterRequest) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) Component(org.springframework.stereotype.Component) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) AmbariDatabaseMapper(com.sequenceiq.cloudbreak.converter.mapper.AmbariDatabaseMapper) Optional(java.util.Optional) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) LdapConfigService(com.sequenceiq.cloudbreak.service.ldapconfig.LdapConfigService) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) LdapConfig(com.sequenceiq.cloudbreak.domain.LdapConfig) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) RDSConfigRequest(com.sequenceiq.cloudbreak.api.model.rds.RDSConfigRequest)

Example 44 with RDSConfig

use of com.sequenceiq.cloudbreak.domain.RDSConfig in project cloudbreak by hortonworks.

the class ClusterTerminationService method finalizeClusterTermination.

public void finalizeClusterTermination(Long clusterId) {
    Cluster cluster = clusterRepository.findById(clusterId);
    Set<RDSConfig> rdsConfigs = cluster.getRdsConfigs();
    Long stackId = cluster.getStack().getId();
    String terminatedName = cluster.getName() + DELIMITER + new Date().getTime();
    cluster.setName(terminatedName);
    FileSystem fs = cluster.getFileSystem();
    if (fs != null) {
        deleteFileSystemResources(stackId, fs);
    }
    cluster.setBlueprint(null);
    cluster.setStack(null);
    cluster.setLdapConfig(null);
    cluster.setRdsConfigs(new HashSet<>());
    cluster.setProxyConfig(null);
    cluster.setStatus(DELETE_COMPLETED);
    deleteClusterHostGroupsWithItsMetadata(cluster);
    rdsConfigService.deleteDefaultRdsConfigs(rdsConfigs);
    componentConfigProvider.deleteComponentsForStack(stackId);
}
Also used : RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) Date(java.util.Date)

Example 45 with RDSConfig

use of com.sequenceiq.cloudbreak.domain.RDSConfig in project cloudbreak by hortonworks.

the class TestUtil method cluster.

public static Cluster cluster(Blueprint blueprint, Stack stack, Long id, KerberosConfig kerberosConfig) {
    Cluster cluster = new Cluster();
    cluster.setAmbariIp("50.51.52.100");
    cluster.setStack(stack);
    cluster.setId(id);
    cluster.setName("dummyCluster");
    cluster.setAmbariIp("10.0.0.1");
    cluster.setBlueprint(blueprint);
    cluster.setUpSince(new Date().getTime());
    cluster.setStatus(AVAILABLE);
    cluster.setStatusReason("statusReason");
    cluster.setUserName("admin");
    cluster.setPassword("admin");
    Gateway gateway = new Gateway();
    gateway.setEnableGateway(true);
    gateway.setTopologyName("cb");
    cluster.setGateway(gateway);
    cluster.setExecutorType(ExecutorType.DEFAULT);
    RDSConfig rdsConfig = new RDSConfig();
    Set<RDSConfig> rdsConfigs = new HashSet<>();
    rdsConfigs.add(rdsConfig);
    cluster.setRdsConfigs(rdsConfigs);
    cluster.setLdapConfig(ldapConfig());
    cluster.setHostGroups(hostGroups(cluster));
    Map<String, String> inputs = new HashMap<>();
    inputs.put("S3_BUCKET", "testbucket");
    try {
        cluster.setBlueprintInputs(new Json(inputs));
    } catch (JsonProcessingException ignored) {
        cluster.setBlueprintInputs(null);
    }
    Map<String, String> map = new HashMap<>();
    try {
        cluster.setAttributes(new Json(map));
    } catch (JsonProcessingException ignored) {
        cluster.setAttributes(null);
    }
    if (kerberosConfig != null) {
        cluster.setSecure(true);
        cluster.setKerberosConfig(kerberosConfig);
    }
    return cluster;
}
Also used : HashMap(java.util.HashMap) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) JsonToString(com.sequenceiq.cloudbreak.domain.json.JsonToString) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)47 Test (org.junit.Test)16 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)7 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)6 RDSConfigRequest (com.sequenceiq.cloudbreak.api.model.rds.RDSConfigRequest)5 Date (java.util.Date)5 HashSet (java.util.HashSet)5 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)4 Json (com.sequenceiq.cloudbreak.domain.json.Json)4 IOException (java.io.IOException)4 APIResourceType (com.sequenceiq.cloudbreak.common.type.APIResourceType)3 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)2 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)2 ConfigsResponse (com.sequenceiq.cloudbreak.api.model.ConfigsResponse)2 RdsView (com.sequenceiq.cloudbreak.blueprint.template.views.RdsView)2 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)2