use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class CleanupFreeIpaHandler method accept.
@Override
public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) {
CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData();
try {
LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
Stack stack = stackService.get(event.getResourceId());
if (event.isRecover()) {
LOGGER.debug("Invoke cleanup on recover");
freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps());
} else {
LOGGER.debug("Invoke cleanup on scale");
freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps());
}
LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
} catch (Exception e) {
LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e);
} finally {
CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover());
Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response);
eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class RegisterPublicDnsHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<RegisterPublicDnsRequest> event) {
RegisterPublicDnsRequest request = event.getData();
Stack stack = request.getStack();
if (gatewayPublicEndpointManagementService.isCertRenewalTriggerable(stack)) {
try {
LOGGER.debug("Fetching instance group and instance metadata for stack.");
InstanceGroup instanceGroup = instanceGroupService.getPrimaryGatewayInstanceGroupByStackId(stack.getId());
List<InstanceMetaData> instanceMetaData = instanceMetaDataService.findAliveInstancesInInstanceGroup(instanceGroup.getId());
if (!instanceMetaData.isEmpty()) {
stack.getInstanceGroups().stream().filter(ig -> ig.getId().equals(instanceGroup.getId())).forEach(ig -> ig.setInstanceMetaData(Set.copyOf(instanceMetaData)));
LOGGER.debug("Registering load balancer public DNS entry");
boolean success = clusterPublicEndpointManagementService.provisionLoadBalancer(stack);
if (!success) {
throw new CloudbreakException("Public DNS registration resulted in failed state. Please consult DNS registration logs.");
}
LOGGER.debug("Load balancer public DNS registration was successful");
return new RegisterPublicDnsSuccess(stack);
} else {
throw new CloudbreakException("Unable to find instance metadata for primary instance group. Certificates cannot " + "be updated.");
}
} catch (Exception e) {
LOGGER.warn("Failed to register load balancer public DNS entries.", e);
return new RegisterPublicDnsFailure(request.getResourceId(), e);
}
} else {
LOGGER.info("Certificates and DNS are not managed by PEM for stack {}. Skipping public DNS registration.", stack.getName());
return new RegisterPublicDnsSuccess(stack);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class UpdateServiceConfigHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<UpdateServiceConfigRequest> event) {
UpdateServiceConfigRequest request = event.getData();
Stack stack = request.getStack();
requireNonNull(stack);
requireNonNull(stack.getCluster());
try {
LOGGER.debug("Gathering entries for Hue knox_proxyhosts property.");
Set<String> proxyhosts = new HashSet<>();
if (StringUtils.isNotEmpty(stack.getPrimaryGatewayInstance().getDiscoveryFQDN())) {
proxyhosts.add(stack.getPrimaryGatewayInstance().getDiscoveryFQDN());
}
if (StringUtils.isNotEmpty(stack.getPrimaryGatewayInstance().getDiscoveryFQDN())) {
proxyhosts.add(stack.getCluster().getFqdn());
}
String loadBalancerFqdn = loadBalancerConfigService.getLoadBalancerUserFacingFQDN(stack.getId());
if (StringUtils.isNotEmpty(loadBalancerFqdn)) {
proxyhosts.add(loadBalancerFqdn);
}
LOGGER.debug("Hue knox_proxyhosts setting will be updated to {}", proxyhosts);
ClusterApi clusterApi = clusterApiConnectors.getConnector(stackService.getByIdWithListsInTransaction(event.getData().getResourceId()));
clusterApi.clusterModificationService().updateServiceConfigAndRestartService(HUE_SERVICE, HUE_KNOX_PROXYHOSTS, String.join(",", proxyhosts));
LOGGER.debug("Updating CM frontend URL with load balancer DNS");
clusterHostServiceRunner.updateClusterConfigs(stack, stack.getCluster());
LOGGER.debug("Service config update was successful");
return new UpdateServiceConfigSuccess(stack);
} catch (Exception e) {
LOGGER.warn("Error updating HUE and CM service configuration.", e);
return new UpdateServiceConfigFailure(request.getResourceId(), e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class UpdateDomainDnsResolverHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<UpdateDomainDnsResolverRequest> updateDomainDnsResolverRequestHandlerEvent) {
UpdateDomainDnsResolverRequest event = updateDomainDnsResolverRequestHandlerEvent.getData();
try {
Stack stack = stackService.getByIdWithLists(event.getResourceId());
DnsResolverType actualDnsResolverType = targetedUpscaleSupportService.getActualDnsResolverType(stack);
if (!actualDnsResolverType.equals(stack.getDomainDnsResolver())) {
LOGGER.debug("New value of domainDnsResolver field for stack {} is {}", stack.getResourceCrn(), actualDnsResolverType);
stack.setDomainDnsResolver(actualDnsResolverType);
stackService.save(stack);
LOGGER.debug("domainDnsResolver field of stack {} has been successfully updated!", stack.getResourceCrn());
} else {
LOGGER.debug("Currently set and actual domainDnsResolverType is the same, not need for update, value {}", actualDnsResolverType);
}
} catch (Exception e) {
LOGGER.debug("We couldn't update domainDnsResolver field of stack, so we move on with current value of the field.", e);
}
return new UpdateDomainDnsResolverResult(event.getResourceId());
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class CreateCloudLoadBalancersHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
CreateCloudLoadBalancersRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
LOGGER.info("Updating cloud stack with load balancer network information");
CloudStack origCloudStack = request.getCloudStack();
Stack stack = request.getStack();
CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
LOGGER.debug("Initiating cloud load balancer creation");
List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
LOGGER.debug("Waiting for cloud load balancers to be fully created");
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
throw new CloudbreakException("Creation failed for load balancers: " + names);
}
Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
return new CreateCloudLoadBalancersSuccess(stack);
} catch (Exception e) {
LOGGER.warn("Failed to created cloud load balance resources.", e);
return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
}
}
Aggregations