Search in sources :

Example 56 with Blueprint

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

the class StackService method validateHostGroupAdjustment.

private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
    Blueprint blueprint = stack.getCluster().getBlueprint();
    Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
    if (!hostGroup.isPresent()) {
        throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
    }
    blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IdentityUserRole(com.sequenceiq.cloudbreak.common.model.user.IdentityUserRole) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) Component(com.sequenceiq.cloudbreak.domain.Component) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) PasswordUtil(com.sequenceiq.cloudbreak.util.PasswordUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Strings(com.google.api.client.repackaged.com.google.common.base.Strings) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) OrchestratorRepository(com.sequenceiq.cloudbreak.repository.OrchestratorRepository) AmbariClusterService(com.sequenceiq.cloudbreak.service.cluster.AmbariClusterService) TxType(javax.transaction.Transactional.TxType) StackViewRepository(com.sequenceiq.cloudbreak.repository.StackViewRepository) Transactional(javax.transaction.Transactional) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) List(java.util.List) STOPPED(com.sequenceiq.cloudbreak.api.model.Status.STOPPED) STOP_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) Optional(java.util.Optional) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) StackStatusRepository(com.sequenceiq.cloudbreak.repository.StackStatusRepository) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Service(org.springframework.stereotype.Service) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Objects.requireNonNull(java.util.Objects.requireNonNull) StackResponseDecorator(com.sequenceiq.cloudbreak.service.decorator.StackResponseDecorator) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Json(com.sequenceiq.cloudbreak.domain.json.Json) Stack(com.sequenceiq.cloudbreak.domain.Stack) Nonnull(javax.annotation.Nonnull) ConversionService(org.springframework.core.convert.ConversionService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SecurityConfigRepository(com.sequenceiq.cloudbreak.repository.SecurityConfigRepository) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) OpenSshPublicKeyValidator(com.sequenceiq.cloudbreak.service.credential.OpenSshPublicKeyValidator) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) NetworkConfigurationValidator(com.sequenceiq.cloudbreak.controller.validation.network.NetworkConfigurationValidator) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) StatusRequest(com.sequenceiq.cloudbreak.api.model.StatusRequest) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 57 with Blueprint

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

the class StackValidationRequestToStackValidationConverter method validateBlueprint.

private void validateBlueprint(StackValidationRequest stackValidationRequest, StackValidation stackValidation) {
    if (stackValidationRequest.getBlueprintId() != null) {
        Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintId());
        stackValidation.setBlueprint(blueprint);
    } else if (stackValidationRequest.getBlueprintName() != null) {
        Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintName(), stackValidationRequest.getAccount());
        stackValidation.setBlueprint(blueprint);
    } else if (stackValidationRequest.getBlueprint() != null) {
        Blueprint blueprint = conversionService.convert(stackValidationRequest.getBlueprint(), Blueprint.class);
        stackValidation.setBlueprint(blueprint);
    } else {
        throw new BadRequestException("Blueprint is not configured for the validation request!");
    }
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 58 with Blueprint

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

the class ClusterToClusterResponseConverter method prepareServiceEndpointsMap.

private Map<String, String> prepareServiceEndpointsMap(Cluster cluster, String ambariIp) {
    Set<HostGroup> hostGroups = cluster.getHostGroups();
    Blueprint blueprint = cluster.getBlueprint();
    Map<String, String> result = new HashMap<>();
    List<Port> ports = NetworkUtils.getPorts(Optional.empty());
    try {
        JsonNode hostGroupsNode = blueprintValidator.getHostGroupNode(blueprint);
        Map<String, HostGroup> hostGroupMap = blueprintValidator.createHostGroupMap(hostGroups);
        for (JsonNode hostGroupNode : hostGroupsNode) {
            String hostGroupName = blueprintValidator.getHostGroupName(hostGroupNode);
            JsonNode componentsNode = blueprintValidator.getComponentsNode(hostGroupNode);
            HostGroup actualHostgroup = hostGroupMap.get(hostGroupName);
            String serviceAddress;
            if (actualHostgroup.getConstraint().getInstanceGroup() != null) {
                InstanceMetaData next = actualHostgroup.getConstraint().getInstanceGroup().getInstanceMetaData().iterator().next();
                serviceAddress = next.getPublicIpWrapper();
            } else {
                serviceAddress = actualHostgroup.getHostMetadata().iterator().next().getHostName();
            }
            for (JsonNode componentNode : componentsNode) {
                String componentName = componentNode.get("name").asText();
                StackServiceComponentDescriptor componentDescriptor = stackServiceComponentDescs.get(componentName);
                collectServicePorts(result, ports, ambariIp, serviceAddress, componentDescriptor, cluster);
            }
        }
    } catch (Exception ignored) {
        return result;
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Port(com.sequenceiq.cloudbreak.api.model.Port) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) IOException(java.io.IOException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) StackServiceComponentDescriptor(com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor)

Example 59 with Blueprint

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

the class BlueprintRequestToBlueprintConverter method convert.

public Blueprint convert(String name, String blueprintText, boolean publicInAccount) {
    Blueprint blueprint = new Blueprint();
    blueprint.setName(name);
    blueprint.setBlueprintText(blueprintText);
    blueprint.setPublicInAccount(publicInAccount);
    validateBlueprint(blueprint.getBlueprintText());
    try {
        JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
        blueprint.setAmbariName(blueprintUtils.getBlueprintName(root));
        blueprint.setHostGroupCount(blueprintUtils.countHostGroups(root));
    } catch (IOException e) {
        throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
    }
    return blueprint;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 60 with Blueprint

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

the class BlueprintRequestToBlueprintConverter method convert.

@Override
public Blueprint convert(BlueprintRequest json) {
    Blueprint blueprint = new Blueprint();
    if (json.getUrl() != null && !json.getUrl().isEmpty()) {
        String sourceUrl = json.getUrl().trim();
        try {
            String urlText = URLUtils.readUrl(sourceUrl);
            jsonHelper.createJsonFromString(urlText);
            blueprint.setBlueprintText(urlText);
        } catch (Exception e) {
            throw new BadRequestException("Cannot download ambari validation from: " + sourceUrl, e);
        }
    } else {
        blueprint.setBlueprintText(json.getAmbariBlueprint());
    }
    validateBlueprint(blueprint.getBlueprintText());
    if (Strings.isNullOrEmpty(json.getName())) {
        blueprint.setName(missingResourceNameGenerator.generateName(APIResourceType.BLUEPRINT));
    } else {
        blueprint.setName(json.getName());
    }
    blueprint.setDescription(json.getDescription());
    blueprint.setStatus(ResourceStatus.USER_MANAGED);
    prepareBlueprintInputs(json, blueprint);
    try {
        JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
        blueprint.setAmbariName(blueprintUtils.getBlueprintName(root));
        blueprint.setHostGroupCount(blueprintUtils.countHostGroups(root));
    } catch (IOException e) {
        throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
    }
    return blueprint;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)71 Test (org.junit.Test)29 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)22 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)7 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)6 List (java.util.List)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)4 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)4 BlueprintTextProcessor (com.sequenceiq.cloudbreak.blueprint.BlueprintTextProcessor)4