use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method changePrimaryGateway.
public String changePrimaryGateway(Stack stack) throws CloudbreakException {
GatewayConfig formerPrimaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
Optional<GatewayConfig> newPrimaryCandidate = gatewayConfigs.stream().filter(gc -> !gc.isPrimary()).findFirst();
if (newPrimaryCandidate.isPresent()) {
GatewayConfig newPrimary = newPrimaryCandidate.get();
Set<Node> allNodes = stackUtil.collectNodes(stack);
try {
hostOrchestrator.changePrimaryGateway(formerPrimaryGatewayConfig, newPrimary, gatewayConfigs, allNodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
return newPrimary.getHostname();
} catch (CloudbreakOrchestratorException ex) {
throw new CloudbreakException(ex);
}
} else {
throw new CloudbreakException("Primary gateway change is not possible because there is no available node for the action");
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method getRangerFqdn.
private List<String> getRangerFqdn(Cluster cluster, String primaryGatewayFqdn, List<String> rangerLocations) {
if (rangerLocations.size() > 1) {
// SDX HA has multiple ranger instances in different groups, in Knox we only want to expose the ones on the gateway.
InstanceGroup gatewayInstanceGroup = instanceGroupService.getPrimaryGatewayInstanceGroupByStackId(cluster.getStack().getId());
String gatewayGroupName = gatewayInstanceGroup.getGroupName();
List<String> hosts = rangerLocations.stream().filter(s -> s.contains(gatewayGroupName)).collect(Collectors.toList());
return hosts;
}
return rangerLocations.contains(primaryGatewayFqdn) ? asList(primaryGatewayFqdn) : asList(rangerLocations.iterator().next());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayService method primaryGatewayChanged.
public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException, TransactionExecutionException {
LOGGER.info("Update primary gateway ip");
Set<InstanceMetaData> imds = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN() != null && imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
InstanceMetaData fpg = formerPrimaryGateway.get();
fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
fpg.setServer(Boolean.FALSE);
transactionService.required(() -> {
instanceMetaDataService.save(fpg);
InstanceMetaData npg = newPrimaryGateway.get();
npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
npg.setServer(Boolean.TRUE);
instanceMetaDataService.save(npg);
Stack updatedStack = stackService.getByIdWithListsInTransaction(stackId);
String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
Cluster cluster = updatedStack.getCluster();
cluster.setClusterManagerIp(gatewayIp);
LOGGER.info("Primary gateway IP has been updated to: '{}'", gatewayIp);
clusterService.save(cluster);
clusterPublicEndpointManagementService.changeGateway(updatedStack);
return null;
});
} else {
throw new CloudbreakException("Primary gateway change was not successful.");
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY 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.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method setupKnoxTargetGroup.
private Optional<TargetGroup> setupKnoxTargetGroup(Stack stack, boolean dryRun) {
TargetGroup knoxTargetGroup = null;
Set<String> knoxGatewayGroupNames = getKnoxGatewayGroups(stack);
Set<InstanceGroup> knoxGatewayInstanceGroups = stack.getInstanceGroups().stream().filter(ig -> knoxGatewayGroupNames.contains(ig.getGroupName())).collect(Collectors.toSet());
if (AZURE.equalsIgnoreCase(stack.getCloudPlatform()) && knoxGatewayInstanceGroups.size() > 1) {
throw new CloudbreakServiceException("For Azure load balancers, Knox must be defined in a single instance group.");
} else if (!knoxGatewayInstanceGroups.isEmpty()) {
LOGGER.info("Knox gateway instance found; enabling Knox load balancer configuration.");
knoxTargetGroup = new TargetGroup();
knoxTargetGroup.setType(TargetGroupType.KNOX);
knoxTargetGroup.setInstanceGroups(knoxGatewayInstanceGroups);
if (!dryRun) {
LOGGER.debug("Adding target group to Knox gateway instances groups.");
TargetGroup finalKnoxTargetGroup = knoxTargetGroup;
knoxGatewayInstanceGroups.forEach(ig -> ig.addTargetGroup(finalKnoxTargetGroup));
} else {
LOGGER.debug("Dry run, skipping instance group/target group linkage.");
}
}
return Optional.ofNullable(knoxTargetGroup);
}
Aggregations