use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class CreateLoadBalancerEntityHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateLoadBalancerEntityRequest> event) {
CreateLoadBalancerEntityRequest request = event.getData();
Stack stack = stackService.getById(request.getResourceId());
try {
LOGGER.debug("Creating load balancer entity objects for stack {}", stack.getId());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
if (environment != null && environment.getNetwork() != null && PublicEndpointAccessGateway.ENABLED.equals(environment.getNetwork().getPublicEndpointAccessGateway())) {
enableEndpointGateway(stack, environment);
}
Set<InstanceGroup> instanceGroups = instanceGroupService.getByStackAndFetchTemplates(stack.getId());
instanceGroups.forEach(ig -> ig.setTargetGroups(targetGroupPersistenceService.findByInstanceGroupId(ig.getId())));
Set<LoadBalancer> existingLoadBalancers = loadBalancerPersistenceService.findByStackId(stack.getId());
stack.setInstanceGroups(instanceGroups);
Set<LoadBalancer> newLoadBalancers = loadBalancerConfigService.createLoadBalancers(stack, environment, null);
Stack savedStack;
if (doLoadBalancersAlreadyExist(existingLoadBalancers, newLoadBalancers)) {
LOGGER.debug("Load balancer entities already exist. Continuing flow.");
savedStack = stack;
} else {
LOGGER.debug("Persisting stack and load balancer objects to database.");
stack.setLoadBalancers(newLoadBalancers);
String stackName = stack.getName();
savedStack = measure(() -> stackService.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
measure(() -> loadBalancerPersistenceService.saveAll(newLoadBalancers), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
measure(() -> targetGroupPersistenceService.saveAll(newLoadBalancers.stream().flatMap(lb -> lb.getTargetGroupSet().stream()).collect(Collectors.toSet())), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
measure(() -> instanceGroupService.saveAll(newLoadBalancers.stream().flatMap(lb -> lb.getAllInstanceGroups().stream()).collect(Collectors.toSet())), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
if (stack.getNetwork() != null) {
measure(() -> networkService.pureSave(stack.getNetwork()), LOGGER, "Network saved in {} ms for stack {}", stackName);
}
}
LOGGER.debug("Load balancer entities successfully persisted.");
savedStack.setInstanceGroups(newLoadBalancers.stream().flatMap(lb -> lb.getAllInstanceGroups().stream()).collect(Collectors.toSet()));
savedStack.setNetwork(stack.getNetwork());
return new CreateLoadBalancerEntitySuccess(request.getResourceId(), savedStack);
} catch (Exception e) {
LOGGER.warn("Failed create load balancer entities and persist them to the database.", e);
return new CreateLoadBalancerEntityFailure(request.getResourceId(), e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterUpgradeFailedCmSyncHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeFailedCmSyncRequest> event) {
ClusterUpgradeFailedCmSyncRequest request = event.getData();
try {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
cmSyncerService.syncFromCmToDb(stack, request.getCandidateImages());
} catch (Exception e) {
LOGGER.warn("Error during syncing CM version to DB, syncing skipped.", e);
}
return new ClusterUpgradeFailHandledRequest(request.getResourceId(), request.getException(), request.getDetailedStatus());
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterUpgradeHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeRequest> event) {
LOGGER.debug("Accepting Cluster upgrade event..");
ClusterUpgradeRequest request = event.getData();
Long stackId = request.getResourceId();
Selectable result;
try {
Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
Optional<String> remoteDataContext = getRemoteDataContext(stack);
ClusterApi connector = clusterApiConnectors.getConnector(stack);
Set<ClusterComponent> components = parcelService.getParcelComponentsByBlueprint(stack);
connector.upgradeClusterRuntime(components, request.isPatchUpgrade(), remoteDataContext);
ParcelOperationStatus parcelOperationStatus = parcelService.removeUnusedParcelComponents(stack, components);
if (parcelOperationStatus.getFailed().isEmpty()) {
result = new ClusterUpgradeSuccess(request.getResourceId());
} else {
LOGGER.info("There are failed parcel removals: {}", parcelOperationStatus);
CloudbreakException exception = new CloudbreakException(format("Failed to remove the following parcels: %s", parcelOperationStatus.getFailed()));
result = new ClusterUpgradeFailedEvent(request.getResourceId(), exception, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
}
} catch (Exception e) {
LOGGER.error("Cluster upgrade event failed", e);
result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class LdapSSOConfigurationHandler method accept.
@Override
public void accept(Event<LdapSSOConfigurationRequest> ldapConfigurationRequestEvent) {
Long stackId = ldapConfigurationRequestEvent.getData().getResourceId();
Selectable response;
try {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
LdapView ldapView = ldapConfigService.get(stack.getEnvironmentCrn(), stack.getName()).orElse(null);
String environmentCrnForVirtualGroups = environmentConfigProvider.getParentEnvironmentCrn(stack.getEnvironmentCrn());
VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(environmentCrnForVirtualGroups, ldapView != null ? ldapView.getAdminGroup() : "");
clusterApiConnectors.getConnector(stack).clusterSecurityService().setupLdapAndSSO(primaryGatewayConfig.getPublicAddress(), ldapView, virtualGroupRequest);
response = new LdapSSOConfigurationSuccess(stackId);
} catch (Exception e) {
LOGGER.info("Error during LDAP configuration, stackId: " + stackId, e);
response = new LdapSSOConfigurationFailed(stackId, e);
}
eventBus.notify(response.selector(), new Event<>(ldapConfigurationRequestEvent.getHeaders(), response));
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClouderaManagerClusterCreationSetupService method filterParcelsIfNecessary.
private Set<ClouderaManagerProduct> filterParcelsIfNecessary(Cluster cluster, Set<ClouderaManagerProduct> products) {
Stack stack = cluster.getStack();
if (stack.isDatalake()) {
return Set.of(clouderaManagerProductsProvider.getCdhProducts(products));
} else {
LOGGER.info("Product list before filter out products by blueprint: {}", products);
Set<ClouderaManagerProduct> filteredProducts = parcelFilterService.filterParcelsByBlueprint(stack.getId(), products, cluster.getBlueprint());
LOGGER.info("Product list after filter out products by blueprint: {}", filteredProducts);
return filteredProducts;
}
}
Aggregations