Search in sources :

Example 1 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method updateStatus.

@Override
@Transactional(TxType.NEVER)
public void updateStatus(Long stackId, StatusRequest statusRequest) {
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = stack.getCluster();
    if (cluster == null) {
        throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
    }
    switch(statusRequest) {
        case SYNC:
            sync(stack);
            break;
        case STOPPED:
            stop(stack, cluster);
            break;
        case STARTED:
            start(stack, cluster);
            break;
        default:
            throw new BadRequestException("Cannot update the status of cluster because status request not valid");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack) Transactional(javax.transaction.Transactional)

Example 2 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method updateUserNamePassword.

@Override
public void updateUserNamePassword(Long stackId, UserNamePasswordJson userNamePasswordJson) {
    Stack stack = stackService.get(stackId);
    Cluster cluster = stack.getCluster();
    String oldUserName = cluster.getUserName();
    String oldPassword = cluster.getPassword();
    String newUserName = userNamePasswordJson.getUserName();
    String newPassword = userNamePasswordJson.getPassword();
    if (!newUserName.equals(oldUserName)) {
        flowManager.triggerClusterCredentialReplace(stack.getId(), userNamePasswordJson.getUserName(), userNamePasswordJson.getPassword());
    } else if (!newPassword.equals(oldPassword)) {
        flowManager.triggerClusterCredentialUpdate(stack.getId(), userNamePasswordJson.getPassword());
    } else {
        throw new BadRequestException("The request may not change credential");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 3 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method validateComponentsCategory.

private void validateComponentsCategory(Stack stack, String hostGroup) {
    Blueprint blueprint = stack.getCluster().getBlueprint();
    try {
        JsonNode root = JsonUtil.readTree(blueprint.getBlueprintText());
        String blueprintName = root.path("Blueprints").path("blueprint_name").asText();
        AmbariClient ambariClient = getAmbariClient(stack);
        Map<String, String> categories = ambariClient.getComponentsCategory(blueprintName, hostGroup);
        for (Entry<String, String> entry : categories.entrySet()) {
            if (entry.getValue().equalsIgnoreCase(MASTER_CATEGORY)) {
                throw new BadRequestException(String.format("Cannot downscale the '%s' hostGroupAdjustment group, because it contains a '%s' component", hostGroup, entry.getKey()));
            }
        }
    } catch (IOException e) {
        LOGGER.warn("Cannot check the host components category", e);
    }
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 4 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method failureReport.

@Override
public void failureReport(Long stackId, List<String> failedNodes) {
    Stack stack = stackService.get(stackId);
    Cluster cluster = stack.getCluster();
    Map<String, List<String>> autoRecoveryNodesMap = new HashMap<>();
    Map<String, HostMetadata> autoRecoveryHostMetadata = new HashMap<>();
    Map<String, HostMetadata> failedHostMetadata = new HashMap<>();
    for (String failedNode : failedNodes) {
        HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(cluster.getId(), failedNode);
        if (hostMetadata == null) {
            throw new BadRequestException("No metadata information for the node: " + failedNode);
        }
        HostGroup hostGroup = hostMetadata.getHostGroup();
        if (hostGroup.getRecoveryMode() == RecoveryMode.AUTO) {
            validateRepair(stack, hostMetadata);
        }
        String hostGroupName = hostGroup.getName();
        if (hostGroup.getRecoveryMode() == RecoveryMode.AUTO) {
            List<String> nodeList = autoRecoveryNodesMap.get(hostGroupName);
            if (nodeList == null) {
                validateComponentsCategory(stack, hostGroupName);
                nodeList = new ArrayList<>();
                autoRecoveryNodesMap.put(hostGroupName, nodeList);
            }
            nodeList.add(failedNode);
            autoRecoveryHostMetadata.put(failedNode, hostMetadata);
        } else if (hostGroup.getRecoveryMode() == RecoveryMode.MANUAL) {
            failedHostMetadata.put(failedNode, hostMetadata);
        }
    }
    if (!autoRecoveryNodesMap.isEmpty()) {
        flowManager.triggerClusterRepairFlow(stackId, autoRecoveryNodesMap, false);
        String recoveryMessage = cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_AUTORECOVERY_REQUESTED.code(), Collections.singletonList(autoRecoveryNodesMap));
        updateChangedHosts(cluster, autoRecoveryHostMetadata, HostMetadataState.HEALTHY, HostMetadataState.WAITING_FOR_REPAIR, recoveryMessage);
    }
    if (!failedHostMetadata.isEmpty()) {
        String recoveryMessage = cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_FAILED_NODES_REPORTED.code(), Collections.singletonList(failedHostMetadata.keySet()));
        updateChangedHosts(cluster, failedHostMetadata, HostMetadataState.HEALTHY, HostMetadataState.UNHEALTHY, recoveryMessage);
    }
}
Also used : HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ArrayList(java.util.ArrayList) List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 5 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method upgrade.

@Override
public void upgrade(Long stackId, AmbariRepo ambariRepoUpgrade) {
    if (ambariRepoUpgrade != null) {
        Stack stack = stackService.getByIdWithLists(stackId);
        Cluster cluster = clusterRepository.findById(stack.getCluster().getId());
        if (cluster == null) {
            throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stackId));
        }
        if (!stack.isAvailable()) {
            throw new BadRequestException(String.format("Stack '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
        }
        if (!cluster.isAvailable()) {
            throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
        }
        AmbariRepo ambariRepo = clusterComponentConfigProvider.getAmbariRepo(cluster.getId());
        if (ambariRepo == null) {
            try {
                clusterComponentConfigProvider.store(new ClusterComponent(ComponentType.AMBARI_REPO_DETAILS, new Json(ambariRepoUpgrade), stack.getCluster()));
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
            }
        } else {
            ClusterComponent component = clusterComponentConfigProvider.getComponent(cluster.getId(), ComponentType.AMBARI_REPO_DETAILS);
            ambariRepo.setBaseUrl(ambariRepoUpgrade.getBaseUrl());
            ambariRepo.setGpgKeyUrl(ambariRepoUpgrade.getGpgKeyUrl());
            ambariRepo.setPredefined(false);
            ambariRepo.setVersion(ambariRepoUpgrade.getVersion());
            try {
                component.setAttributes(new Json(ambariRepo));
                clusterComponentConfigProvider.store(component);
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
            }
        }
        try {
            flowManager.triggerClusterUpgrade(stack.getId());
        } catch (RuntimeException e) {
            throw new CloudbreakServiceException(e);
        }
    }
}
Also used : ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) UserNamePasswordJson(com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3