use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class ConfigureClusterManagerSupportTagsHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ConfigureClusterManagerSupportTagsRequest> event) {
Long stackId = event.getData().getResourceId();
Selectable response;
try {
clusterBuilderService.configureSupportTags(stackId);
response = new ConfigureClusterManagerSupportTagsSuccess(stackId);
} catch (RuntimeException e) {
LOGGER.error("ConfigureClusterManagerSupportTagsHandler step failed with the following message: {}", e.getMessage());
response = new ConfigureClusterManagerSupportTagsFailed(stackId, e);
}
return response;
}
use of com.sequenceiq.cloudbreak.common.event.Selectable 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.common.event.Selectable 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);
}
}
use of com.sequenceiq.cloudbreak.common.event.Selectable 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.common.event.Selectable in project cloudbreak by hortonworks.
the class ClusterManagerUpgradeHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ClusterManagerUpgradeRequest> event) {
LOGGER.debug("Accepting Cluster Manager upgrade event..");
ClusterManagerUpgradeRequest request = event.getData();
Selectable result;
try {
clusterManagerUpgradeService.upgradeClusterManager(request.getResourceId(), request.isRuntimeServicesStartNeeded());
result = new ClusterManagerUpgradeSuccess(request.getResourceId());
} catch (Exception e) {
LOGGER.info("Cluster Manager upgrade event failed", e);
result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
}
return result;
}
Aggregations