use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterOperationService method updateHosts.
public FlowIdentifier updateHosts(Long stackId, HostGroupAdjustmentV4Request hostGroupAdjustment) {
Stack stack = stackService.getById(stackId);
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
}
boolean downscaleRequest = updateHostsValidator.validateRequest(stack, hostGroupAdjustment);
if (downscaleRequest) {
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + abs(hostGroupAdjustment.getScalingAdjustment()));
return flowManager.triggerClusterDownscale(stackId, hostGroupAdjustment);
} else {
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + hostGroupAdjustment.getScalingAdjustment());
return flowManager.triggerClusterUpscale(stackId, hostGroupAdjustment);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterOperationService method create.
@Measure(ClusterOperationService.class)
public Cluster create(Stack stack, Cluster cluster, List<ClusterComponent> components, User user) throws TransactionService.TransactionExecutionException {
LOGGER.debug("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
String stackName = stack.getName();
if (stack.getCluster() != null) {
throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
}
long start = System.currentTimeMillis();
return transactionService.required(() -> {
setWorkspace(cluster, stack.getWorkspace());
cluster.setEnvironmentCrn(stack.getEnvironmentCrn());
if (Status.CREATE_FAILED.equals(stack.getStatus())) {
throw new BadRequestException("Stack creation failed, cannot create cluster.");
}
if (cluster.getFileSystem() != null) {
cluster.setFileSystem(fileSystemConfigService.createWithMdcContextRestore(cluster.getFileSystem(), cluster.getWorkspace(), user));
}
removeGatewayIfNotSupported(cluster, components);
cluster.setStack(stack);
stack.setCluster(cluster);
Cluster savedCluster = measure(() -> clusterService.saveClusterAndComponent(cluster, components, stackName), LOGGER, "saveClusterAndComponent {} ms");
measure(() -> usageLoggingUtil.logClusterRequestedUsageEvent(cluster), LOGGER, "logClusterRequestedUsageEvent {} ms");
LOGGER.info("cluster saved {} ms", System.currentTimeMillis() - start);
return savedCluster;
});
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterOperationService method updateUserNamePassword.
public FlowIdentifier updateUserNamePassword(Long stackId, UserNamePasswordV4Request userNamePasswordJson) {
Stack stack = stackService.getById(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)) {
return flowManager.triggerClusterCredentialReplace(stack.getId(), userNamePasswordJson.getUserName(), userNamePasswordJson.getPassword());
} else if (!newPassword.equals(oldPassword)) {
return flowManager.triggerClusterCredentialUpdate(stack.getId(), userNamePasswordJson.getPassword());
} else {
throw new BadRequestException("The request may not change credential");
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterOperationService method removeGatewayIfNotSupported.
private void removeGatewayIfNotSupported(Cluster cluster, List<ClusterComponent> components) {
Optional<ClusterComponent> cmRepoOpt = components.stream().filter(cmp -> ComponentType.CM_REPO_DETAILS.equals(cmp.getComponentType())).findFirst();
if (cmRepoOpt.isPresent()) {
try {
ClouderaManagerRepo cmRepo = cmRepoOpt.get().getAttributes().get(ClouderaManagerRepo.class);
if (!CMRepositoryVersionUtil.isKnoxGatewaySupported(cmRepo)) {
LOGGER.debug("Knox gateway is not supported by CM version: {}, ignoring it for cluster: {}", cmRepo.getVersion(), cluster.getName());
cluster.setGateway(null);
}
} catch (IOException e) {
LOGGER.debug("Failed to read CM repo cluster component", e);
}
}
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterOperationService method updateAutoRecoverableNodes.
private void updateAutoRecoverableNodes(Cluster cluster, Map<String, List<String>> autoRecoveryNodesMap, Map<String, InstanceMetaData> autoRecoveryHostMetadata) throws TransactionExecutionException {
if (!autoRecoveryNodesMap.isEmpty()) {
flowManager.triggerClusterRepairFlow(cluster.getStack().getId(), autoRecoveryNodesMap, false);
Map<String, Optional<String>> hostNamesWithReason = autoRecoveryHostMetadata.keySet().stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY);
InstanceStatus newState = InstanceStatus.WAITING_FOR_REPAIR;
ResourceEvent clusterEvent = CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT;
ResourceEvent hostEvent = CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT;
updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
}
}
Aggregations