Search in sources :

Example 1 with EnvironmentBaseResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse in project cloudbreak by hortonworks.

the class CleanupWaitUtil method checkEnvironmentDeleteFailedStatus.

/**
 * Checking the environment is in DELETE_FAILED state.
 *
 * Returns with:
 * TRUE:   DELETE_FAILED state is available.
 * FALSE:  DELETE_FAILED state is not available.
 *
 * @param environmentClient  com.sequenceiq.environment.client.EnvironmentClient
 * @param environmentName    Provided environment name
 * @return                   TRUE or FALSE based on existing DELETE_FAILED status
 */
private boolean checkEnvironmentDeleteFailedStatus(EnvironmentClient environmentClient, String environmentName) {
    try {
        EnvironmentStatus environmentStatus = environmentClient.environmentV1Endpoint().list().getResponses().stream().filter(response -> response.getName().equalsIgnoreCase(environmentName)).findFirst().map(EnvironmentBaseResponse::getEnvironmentStatus).orElse(EnvironmentStatus.ARCHIVED);
        LOG.info("{} environment actual state is: {}", environmentName, environmentStatus);
        return environmentStatus.equals(EnvironmentStatus.DELETE_FAILED);
    } catch (Exception e) {
        LOG.warn("Exception has been occurred while checking {} environment's DELETE_FAILED state: {}", environmentName, e.getMessage(), e);
        return false;
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) Collectors(java.util.stream.Collectors) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) WaitResult(com.sequenceiq.it.cloudbreak.util.WaitResult) Value(org.springframework.beans.factory.annotation.Value) SdxClient(com.sequenceiq.sdx.client.SdxClient) Component(org.springframework.stereotype.Component) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient) Map(java.util.Map) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) Collections(java.util.Collections) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)

Example 2 with EnvironmentBaseResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverter method convert.

public Stack convert(StackV4Request source) {
    Workspace workspace = workspaceService.getForCurrentUser();
    Stack stack = new Stack();
    stack.setEnvironmentCrn(source.getEnvironmentCrn());
    DetailedEnvironmentResponse environment = null;
    if (!StringUtils.isEmpty(source.getEnvironmentCrn())) {
        environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName());
    }
    if (isTemplate(source)) {
        updateCustomDomainOrKerberos(source, stack);
        updateCloudPlatformAndRelatedFields(source, stack, environment);
        convertAsStackTemplate(source, stack, environment);
        setNetworkAsTemplate(source, stack);
    } else {
        convertAsStack(source, stack);
        updateCloudPlatformAndRelatedFields(source, stack, environment);
        setNetworkIfApplicable(source, stack, environment);
        setInstanceGroupNetworkIfApplicable(source, stack, environment);
        stack.getComponents().add(getTelemetryComponent(stack, source));
    }
    Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
    if (asMap != null) {
        Map<String, String> parameter = new HashMap<>();
        asMap.forEach((key, value) -> parameter.put(key, value.toString()));
        stack.setParameters(parameter);
    }
    setTimeToLive(source, stack);
    stack.setWorkspace(workspace);
    stack.setDisplayName(source.getName());
    stack.setDatalakeCrn(datalakeService.getDatalakeCrn(source, workspace));
    stack.setStackAuthentication(stackAuthenticationV4RequestToStackAuthenticationConverter.convert(source.getAuthentication()));
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED));
    stack.setCreated(clock.getCurrentTimeMillis());
    stack.setInstanceGroups(convertInstanceGroups(source, stack));
    Optional<String> parentEnvCloudPlatform = Optional.ofNullable(environment).map(EnvironmentBaseResponse::getParentEnvironmentCloudPlatform);
    measure(() -> updateCluster(source, stack, parentEnvCloudPlatform), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName());
    stack.setGatewayPort(source.getGatewayPort());
    stack.setUuid(UUID.randomUUID().toString());
    stack.setType(source.getType());
    stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>())));
    if (source.getImage() != null) {
        stack.getComponents().add(getImageComponent(source, stack));
    }
    if (!isTemplate(source) && environment != null) {
        gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel());
    }
    stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType));
    stack.setExternalDatabaseEngineVersion(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getDatabaseEngineVersion));
    stack.setDomainDnsResolver(targetedUpscaleSupportService.isUnboundEliminationSupported(Crn.safeFromString(source.getEnvironmentCrn()).getAccountId()) ? DnsResolverType.FREEIPA_FOR_ENV : DnsResolverType.LOCAL_UNBOUND);
    determineServiceTypeTag(stack, source.getTags());
    determineServiceFeatureTag(stack, source.getTags());
    Set<LoadBalancer> loadBalancers = loadBalancerConfigService.createLoadBalancers(stack, environment, source);
    stack.setLoadBalancers(loadBalancers);
    return stack;
}
Also used : HashMap(java.util.HashMap) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Aggregations

EnvironmentBaseResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 StackInputs (com.sequenceiq.cloudbreak.cloud.model.StackInputs)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)1 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 EnvironmentStatus (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)1 EnvironmentClient (com.sequenceiq.environment.client.EnvironmentClient)1 WaitResult (com.sequenceiq.it.cloudbreak.util.WaitResult)1 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)1 SdxClusterStatusResponse (com.sequenceiq.sdx.api.model.SdxClusterStatusResponse)1 SdxClient (com.sequenceiq.sdx.client.SdxClient)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1