Search in sources :

Example 16 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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 17 with Cluster

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

the class AmbariClusterService method updateClusterStatusByStackId.

@Override
@Transactional(TxType.NEVER)
public Cluster updateClusterStatusByStackId(Long stackId, Status status, String statusReason) {
    LOGGER.debug("Updating cluster status. stackId: {}, status: {}, statusReason: {}", stackId, status, statusReason);
    StackStatus stackStatus = stackService.getCurrentStatusByStackId(stackId);
    Cluster cluster = retrieveClusterByStackId(stackId);
    if (cluster != null) {
        cluster.setStatus(status);
        cluster.setStatusReason(statusReason);
        cluster = clusterRepository.save(cluster);
        if (status.isRemovableStatus()) {
            InMemoryStateStore.deleteCluster(cluster.getId());
            if (stackStatus.getStatus().isRemovableStatus()) {
                InMemoryStateStore.deleteStack(stackId);
            }
        } else {
            InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(status));
            if (InMemoryStateStore.getStack(stackId) == null) {
                InMemoryStateStore.putStack(stackId, statusToPollGroupConverter.convert(stackStatus.getStatus()));
            }
        }
    }
    return cluster;
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Transactional(javax.transaction.Transactional)

Example 18 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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 19 with Cluster

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

the class AmbariClusterService method repairCluster.

@Override
public void repairCluster(Long stackId, List<String> repairedHostGroups, boolean removeOnly) {
    Stack stack = stackService.get(stackId);
    Cluster cluster = stack.getCluster();
    Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
    Map<String, List<String>> failedNodeMap = new HashMap<>();
    for (HostGroup hg : hostGroups) {
        List<String> failedNodes = new ArrayList<>();
        if (repairedHostGroups.contains(hg.getName()) && hg.getRecoveryMode() == RecoveryMode.MANUAL) {
            for (HostMetadata hmd : hg.getHostMetadata()) {
                if (hmd.getHostMetadataState() == HostMetadataState.UNHEALTHY) {
                    validateRepair(stack, hmd);
                    if (!failedNodeMap.containsKey(hg.getName())) {
                        failedNodeMap.put(hg.getName(), failedNodes);
                    }
                    failedNodes.add(hmd.getHostName());
                }
            }
        }
    }
    if (!failedNodeMap.isEmpty()) {
        flowManager.triggerClusterRepairFlow(stackId, failedNodeMap, removeOnly);
        String recoveryMessage = cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_MANUALRECOVERY_REQUESTED.code(), Collections.singletonList(repairedHostGroups));
        LOGGER.info(recoveryMessage);
        eventService.fireCloudbreakEvent(stack.getId(), "RECOVERY", recoveryMessage);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) 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 20 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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

Cluster (com.sequenceiq.cloudbreak.domain.Cluster)144 Stack (com.sequenceiq.cloudbreak.domain.Stack)68 Test (org.junit.Test)64 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)31 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)26 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)22 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)22 HashMap (java.util.HashMap)22 HashSet (java.util.HashSet)15 List (java.util.List)15 ArrayList (java.util.ArrayList)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)11 Matchers.anyString (org.mockito.Matchers.anyString)11 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)10 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)9 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)9