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");
}
}
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");
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations