use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class HdfConfigProviderTest method testNifiNodeIdentitiesWhenMasterIsAvailable.
@Test
public void testNifiNodeIdentitiesWhenMasterIsAvailable() throws IOException {
// GIVEN
String blueprintText = FileReaderUtils.readFileFromClasspath("blueprints-jackson/bp-kerberized-test.bp");
Set<HostGroup> hostGroups = new HashSet<>();
hostGroups.add(TestUtil.hostGroup("master", 2));
hostGroups.add(TestUtil.hostGroup("worker", 2));
hostGroups.add(TestUtil.hostGroup("compute", 2));
Map<String, List<InstanceMetaData>> groupInstanes = new HashMap<>();
for (HostGroup hg : hostGroups) {
groupInstanes.put(hg.getName(), new ArrayList<>(hg.getConstraint().getInstanceGroup().getInstanceMetaData()));
}
when(blueprintProcessor.getHostGroupsWithComponent("NIFI_MASTER")).thenReturn(Sets.newHashSet("master"));
when(blueprintProcessor.pathValue("configurations", "nifi-ambari-config", "nifi.node.ssl.port")).thenReturn(Optional.of("9091"));
when(blueprintProcessorFactory.get(anyString())).thenReturn(blueprintProcessor);
// WHEN
HdfConfigs hdfConfigs = underTest.createHdfConfig(hostGroups, groupInstanes, blueprintText);
// THEN
StringBuilder expectedNodeEntities = new StringBuilder();
int i = 0;
for (InstanceMetaData instance : groupInstanes.get("master")) {
expectedNodeEntities.append("<property name=\"Node Identity " + ++i + "\">CN=" + instance.getDiscoveryFQDN() + ", OU=NIFI</property>");
}
Assert.assertEquals(expectedNodeEntities.toString(), hdfConfigs.getNodeEntities());
Assert.assertEquals(Optional.of(groupInstanes.get("master").stream().map(im -> im.getPublicIp() + ":9091").collect(Collectors.joining(","))), hdfConfigs.getProxyHosts());
verify(blueprintProcessor, times(1)).getHostGroupsWithComponent("NIFI_MASTER");
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayService method primaryGatewayChanged.
@Transactional
public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException {
Set<InstanceMetaData> imds = instanceMetaDataRepository.findNotTerminatedForStack(stackId);
Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
InstanceMetaData fpg = formerPrimaryGateway.get();
fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
instanceMetaDataRepository.save(fpg);
InstanceMetaData npg = newPrimaryGateway.get();
npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
instanceMetaDataRepository.save(npg);
Stack updatedStack = stackService.getByIdWithLists(stackId);
String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
Cluster cluster = updatedStack.getCluster();
cluster.setAmbariIp(gatewayIp);
clusterRepository.save(cluster);
} else {
throw new CloudbreakException("Primary gateway change was not successful.");
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class AmbariClusterResetService method resetCluster.
public void resetCluster(Long stackId) throws CloudbreakOrchestratorException {
Stack stack = stackRepository.findOneWithLists(stackId);
try {
InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, stack.getCluster().getGateway().getEnableGateway());
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
hostOrchestrator.resetAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), exitCriteriaModel);
} else {
throw new UnsupportedOperationException("ambari reset cluster works only with host orchestrator");
}
} catch (CloudbreakException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class AmbariClusterUpgradeService method upgradeCluster.
public void upgradeCluster(Long stackId) throws CloudbreakOrchestratorException {
Stack stack = stackRepository.findOneWithLists(stackId);
Cluster cluster = stack.getCluster();
try {
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.getGateway().getEnableGateway());
Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(cluster.getId());
Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
Map<String, Object> credentials = new HashMap<>();
credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(cluster));
credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(cluster));
servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
if (ambariRepo != null) {
servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
}
SaltConfig pillar = new SaltConfig(servicePillar);
hostOrchestrator.upgradeAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), pillar, exitCriteriaModel);
} else {
throw new UnsupportedOperationException("Ambari upgrade works only with host orchestrator");
}
} catch (CloudbreakException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterRepairFlowEventChainFactory method createFlowTriggerEventQueue.
@Override
public Queue<Selectable> createFlowTriggerEventQueue(ClusterRepairTriggerEvent event) {
StackView stackView = stackService.getByIdView(event.getStackId());
Queue<Selectable> flowChainTriggers = new ConcurrentLinkedDeque<>();
Map<String, List<String>> failedNodesMap = event.getFailedNodesMap();
for (Entry<String, List<String>> failedNodes : failedNodesMap.entrySet()) {
String hostGroupName = failedNodes.getKey();
List<String> hostNames = failedNodes.getValue();
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stackView.getClusterView().getId(), hostGroupName);
InstanceGroup instanceGroup = hostGroup.getConstraint().getInstanceGroup();
if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
List<InstanceMetaData> primary = instanceMetadataRepository.findAllByInstanceGroup(instanceGroup).stream().filter(imd -> hostNames.contains(imd.getDiscoveryFQDN()) && imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).collect(Collectors.toList());
if (!primary.isEmpty()) {
flowChainTriggers.add(new ChangePrimaryGatewayTriggerEvent(ChangePrimaryGatewayEvent.CHANGE_PRIMARY_GATEWAY_TRIGGER_EVENT.event(), event.getStackId(), event.accepted()));
}
}
flowChainTriggers.add(new ClusterAndStackDownscaleTriggerEvent(FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, new HashSet<>(hostNames), ScalingType.DOWNSCALE_TOGETHER, event.accepted()));
if (!event.isRemoveOnly()) {
flowChainTriggers.add(new StackAndClusterUpscaleTriggerEvent(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, hostNames.size(), ScalingType.UPSCALE_TOGETHER, Sets.newHashSet(hostNames)));
// we need to update all ephemeral clusters that are connected to a datalake
if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()) && !stackService.findClustersConnectedToDatalake(event.getStackId()).isEmpty()) {
flowChainTriggers.add(new EphemeralClustersUpgradeTriggerEvent(FlowChainTriggers.EPHEMERAL_CLUSTERS_UPDATE_TRIGGER_EVENT, event.getStackId(), event.accepted()));
}
}
}
return flowChainTriggers;
}
Aggregations