use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StackToStackV4ResponseConverter method getTags.
private TagsV4Response getTags(Json tag) {
try {
if (tag != null && tag.getValue() != null) {
StackTags stackTag = tag.get(StackTags.class);
return stackTagsToTagsV4ResponseConverter.convert(stackTag);
}
} catch (Exception e) {
LOGGER.info("Failed to convert dynamic tags.", e);
}
TagsV4Response response = new TagsV4Response();
response.setApplication(new HashMap<>());
response.setDefaults(new HashMap<>());
response.setUserDefined(new HashMap<>());
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverter method getTags.
private Json getTags(StackV4Request source, DetailedEnvironmentResponse environment) {
try {
TagsV4Request tags = source.getTags();
if (tags == null) {
Map<String, String> userDefined = environment == null || environment.getTags() == null ? new HashMap<>() : environment.getTags().getUserDefined();
return new Json(new StackTags(userDefined, new HashMap<>(), new HashMap<>()));
}
Map<String, String> userDefined = new HashMap<>();
if (environment != null && environment.getTags() != null && environment.getTags().getUserDefined() != null && !environment.getTags().getUserDefined().isEmpty()) {
userDefined = environment.getTags().getUserDefined();
}
CDPTagMergeRequest request = CDPTagMergeRequest.Builder.builder().withPlatform(source.getCloudPlatform().name()).withRequestTags(tags.getUserDefined() != null ? tags.getUserDefined() : Maps.newHashMap()).withEnvironmentTags(userDefined).build();
return new Json(new StackTags(costTagging.mergeTags(request), tags.getApplication(), new HashMap<>()));
} catch (Exception e) {
throw new BadRequestException("Failed to convert dynamic tags. " + e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class ClusterOperationService method updateNewHealthyNodes.
private void updateNewHealthyNodes(Cluster cluster, Set<String> newHealthyNodes) throws TransactionExecutionException {
if (!newHealthyNodes.isEmpty()) {
Map<String, Optional<String>> hostNamesWithReason = newHealthyNodes.stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
Set<InstanceStatus> expectedStates = EnumSet.of(SERVICES_UNHEALTHY, SERVICES_RUNNING, DECOMMISSION_FAILED, FAILED);
InstanceStatus newState = SERVICES_HEALTHY;
ResourceEvent clusterEvent = CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT;
updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.empty());
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StopStartUpscaleCommissionViaCMRequest> event) {
StopStartUpscaleCommissionViaCMRequest request = event.getData();
LOGGER.info("StopStartUpscaleCommissionViaCMHandler for: {}, {}", event.getData().getResourceId(), event);
LOGGER.debug("StartedInstancesToCommission: {}, servicesNotRunningInstancesToCommission: {}", request.getStartedInstancesToCommission(), request.getServicesNotRunningInstancesToCommission());
List<InstanceMetaData> allInstancesToCommission = new LinkedList<>();
allInstancesToCommission.addAll(request.getStartedInstancesToCommission());
allInstancesToCommission.addAll(request.getServicesNotRunningInstancesToCommission());
try {
Stack stack = stackService.getByIdWithLists(request.getResourceId());
Cluster cluster = stack.getCluster();
flowMessageService.fireEventAndLog(stack.getId(), UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_STOPSTART_UPSCALE_WAITING_HOSTSTART, String.valueOf(allInstancesToCommission.size()));
ClusterSetupService clusterSetupService = clusterApiConnectors.getConnector(stack).clusterSetupService();
clusterSetupService.waitForHostsHealthy(new HashSet<>(allInstancesToCommission));
flowMessageService.fireEventAndLog(stack.getId(), UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_STOPSTART_UPSCALE_CMHOSTSSTARTED, String.valueOf(allInstancesToCommission.size()));
ClusterCommissionService clusterCommissionService = clusterApiConnectors.getConnector(stack).clusterCommissionService();
Set<String> hostNames = allInstancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
LOGGER.debug("HostNames to recommission: count={}, hostNames={}", hostNames.size(), hostNames);
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(cluster.getId(), request.getHostGroupName()).orElseThrow(NotFoundException.notFound("hostgroup", request.getHostGroupName()));
Map<String, InstanceMetaData> hostsToRecommission = clusterCommissionService.collectHostsToCommission(hostGroup, hostNames);
List<String> missingHostsInCm = Collections.emptyList();
if (hostNames.size() != hostsToRecommission.size()) {
missingHostsInCm = hostNames.stream().filter(h -> !hostsToRecommission.containsKey(h)).collect(Collectors.toList());
LOGGER.info("Found fewer instances in CM to commission, as compared to initial ask. foundCount={}, initialCount={}, missingHostsInCm={}", hostsToRecommission.size(), hostNames.size(), missingHostsInCm);
}
// TODO CB-15132: Eventually ensure CM, relevant services (YARN RM) are in a functional state - or fail/delay the operation
// TODO CB-15132: Potentially poll nodes for success. Don't fail the entire operation if a single node fails to commission.
// What would need to happen to the CM command in this case? (Can only work in the presence of a co-operative CM API call.
// Alternately this could go straight to the service)
Set<String> recommissionedHostnames = Collections.emptySet();
if (hostsToRecommission.size() > 0) {
recommissionedHostnames = clusterCommissionService.recommissionClusterNodes(hostsToRecommission);
// TODO CB-15132: Maybe wait for services to start / force CM sync.
}
List<String> allMissingRecommissionHostnames = null;
if (missingHostsInCm.size() > 0) {
allMissingRecommissionHostnames = new LinkedList<>(missingHostsInCm);
}
if (hostsToRecommission.size() != recommissionedHostnames.size()) {
Set<String> finalRecommissionedHostnames = recommissionedHostnames;
List<String> additionalMissingRecommissionHostnames = hostsToRecommission.keySet().stream().filter(h -> !finalRecommissionedHostnames.contains(h)).collect(Collectors.toList());
LOGGER.info("Recommissioned fewer instances than requested. recommissionedCount={}, expectedCount={}, initialCount={}, notRecommissioned=[{}]", recommissionedHostnames.size(), hostsToRecommission.size(), hostNames.size(), additionalMissingRecommissionHostnames);
if (allMissingRecommissionHostnames == null) {
allMissingRecommissionHostnames = new LinkedList<>();
}
allMissingRecommissionHostnames.addAll(additionalMissingRecommissionHostnames);
}
return new StopStartUpscaleCommissionViaCMResult(request, recommissionedHostnames, allMissingRecommissionHostnames);
} catch (Exception e) {
// TODO CB-15132: This can be improved based on where and when the Exception occurred to potentially rollback certain aspects.
// ClusterClientInitException is one which is explicitly thrown.
String message = "Failed while attempting to commission nodes via CM";
LOGGER.error(message);
return new StopStartUpscaleCommissionViaCMResult(message, e, request);
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class MetadataSetupService method saveLoadBalancerMetadata.
public void saveLoadBalancerMetadata(Stack stack, Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetadataList) {
try {
LOGGER.info("Save load balancer metadata for stack: {}", stack.getName());
Set<LoadBalancer> allLoadBalancerMetadata = loadBalancerPersistenceService.findByStackId(stack.getId());
for (CloudLoadBalancerMetadata cloudLoadBalancerMetadata : cloudLoadBalancerMetadataList) {
LoadBalancer loadBalancerEntry = createLoadBalancerMetadataIfAbsent(allLoadBalancerMetadata, stack, cloudLoadBalancerMetadata.getType());
loadBalancerEntry.setDns(cloudLoadBalancerMetadata.getCloudDns());
loadBalancerEntry.setHostedZoneId(cloudLoadBalancerMetadata.getHostedZoneId());
loadBalancerEntry.setIp(cloudLoadBalancerMetadata.getIp());
loadBalancerEntry.setType(cloudLoadBalancerMetadata.getType());
String endpoint = loadBalancerConfigService.generateLoadBalancerEndpoint(stack);
List<StackIdView> byEnvironmentCrnAndStackType = stackService.getByEnvironmentCrnAndStackType(stack.getEnvironmentCrn(), StackType.DATALAKE);
List<StackStatus> stoppedDatalakes = byEnvironmentCrnAndStackType.stream().map(s -> stackStatusService.findFirstByStackIdOrderByCreatedDesc(s.getId())).filter(Optional::isPresent).map(Optional::get).filter(status -> status.getStatus().isStopState()).collect(Collectors.toList());
if (!stoppedDatalakes.isEmpty()) {
/* Starts to check for a situation where we are resizing a datalake that did not previously have loadbalancers
so that we can use the same endpoint name for a seamless transistion
*/
LOGGER.info("Using old datalake endpoint name for resized datalake: {}, env: {}", stack.getName(), stack.getEnvironmentCrn());
if (stoppedDatalakes.size() > 1) {
String ids = stoppedDatalakes.stream().map(stackStatus -> stackStatus.getStack().getId()).map(Object::toString).collect(Collectors.joining(","));
LOGGER.warn("more than one datalake found to resize from: {}", ids);
}
Long oldId = stoppedDatalakes.get(0).getStack().getId();
Set<LoadBalancer> oldLoadbalancers = loadBalancerPersistenceService.findByStackId(oldId);
if (oldLoadbalancers.isEmpty()) {
Stack oldStack = stackService.getByIdWithGatewayInTransaction(oldId);
if (stack.getDisplayName().equals(oldStack.getDisplayName())) {
endpoint = oldStack.getPrimaryGatewayInstance().getShortHostname();
}
}
}
LOGGER.info("Saving load balancer endpoint as: {}", endpoint);
loadBalancerEntry.setEndpoint(endpoint);
loadBalancerEntry.setProviderConfig(loadBalancerConfigConverter.convertLoadBalancer(stack.getCloudPlatform(), cloudLoadBalancerMetadata));
loadBalancerPersistenceService.save(loadBalancerEntry);
Set<TargetGroup> targetGroups = targetGroupPersistenceService.findByLoadBalancerId(loadBalancerEntry.getId());
for (TargetGroup targetGroup : targetGroups) {
targetGroup.setProviderConfig(loadBalancerConfigConverter.convertTargetGroup(stack.getCloudPlatform(), cloudLoadBalancerMetadata, targetGroup));
targetGroupPersistenceService.save(targetGroup);
}
}
} catch (Exception ex) {
throw new CloudbreakServiceException("Load balancer metadata collection failed", ex);
}
}
Aggregations