use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class TlsSetupService method setupTls.
public void setupTls(Stack stack, InstanceMetaData gwInstance) throws CloudbreakException {
try {
SavingX509TrustManager x509TrustManager = new SavingX509TrustManager();
TrustManager[] trustManagers = { x509TrustManager };
SSLContext sslContext = SslConfigurator.newInstance().createSSLContext();
sslContext.init(null, trustManagers, new SecureRandom());
Client client = RestClientUtil.createClient(sslContext, false, null);
Integer gatewayPort = stack.getGatewayPort();
String ip = gatewayConfigService.getGatewayIp(stack, gwInstance);
LOGGER.info("Trying to fetch the server's certificate: {}:{}", ip, gatewayPort);
nginxPollerService.pollWithTimeoutSingleFailure(nginxCertListenerTask, new NginxPollerObject(stack, client, ip, gatewayPort, x509TrustManager), POLLING_INTERVAL, MAX_ATTEMPTS_FOR_HOSTS);
WebTarget nginxTarget = client.target(String.format("https://%s:%d", ip, gatewayPort));
nginxTarget.path("/").request().get();
X509Certificate[] chain = x509TrustManager.getChain();
String serverCert = PkiUtil.convert(chain[0]);
InstanceMetaData metaData = instanceMetaDataRepository.findOne(gwInstance.getId());
metaData.setServerCert(BaseEncoding.base64().encode(serverCert.getBytes()));
instanceMetaDataRepository.save(metaData);
} catch (Exception e) {
throw new CloudbreakException("Failed to retrieve the server's certificate", e);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class HostMetadataSetup method setupNewHostMetadata.
public void setupNewHostMetadata(Long stackId, Collection<String> newAddresses) throws CloudbreakException {
LOGGER.info("Extending host metadata.");
Stack stack = stackService.getByIdWithLists(stackId);
if (!orchestratorTypeResolver.resolveType(stack.getOrchestrator()).containerOrchestrator()) {
Set<InstanceMetaData> newInstanceMetadata = stack.getRunningInstanceMetaData().stream().filter(instanceMetaData -> newAddresses.contains(instanceMetaData.getPrivateIp())).collect(Collectors.toSet());
updateWithHostData(stack, newInstanceMetadata);
instanceMetaDataRepository.save(newInstanceMetadata);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class HostMetadataSetup method updateWithHostData.
private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) throws CloudbreakSecuritySetupException {
try {
List<String> privateIps = metadataToUpdate.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
for (InstanceMetaData instanceMetaData : metadataToUpdate) {
instanceMetaData.setConsulServer(false);
String address = members.get(instanceMetaData.getPrivateIp());
instanceMetaData.setDiscoveryFQDN(address);
LOGGER.info("Domain used for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address, instanceMetaData.getDiscoveryFQDN());
}
} catch (Exception e) {
throw new CloudbreakSecuritySetupException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class CandidateUnhealthyInstanceSelector method selectCandidateUnhealthyInstances.
public Set<InstanceMetaData> selectCandidateUnhealthyInstances(long stackId) {
Map<String, String> hostStatuses = clusterService.getHostStatuses(stackId);
LOGGER.info("HostStatuses: {}", hostStatuses);
Set<InstanceMetaData> candidateUnhealthyInstances = new HashSet<>();
hostStatuses.keySet().stream().filter(hostName -> hostName != null && "UNKNOWN".equals(hostStatuses.get(hostName))).forEach(hostName -> {
InstanceMetaData instanceMetaData = instanceMetaDataRepository.findHostInStack(stackId, hostName);
if (isAWorker(instanceMetaData)) {
candidateUnhealthyInstances.add(instanceMetaData);
}
});
LOGGER.info("Candidate Unhealthy Instances: {}", candidateUnhealthyInstances);
return candidateUnhealthyInstances;
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.
public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances);
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
Set<String> unhealthyInstances = new HashSet<>();
for (InstanceMetaData i : candidateUnhealthyInstances) {
CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
unhealthyInstances.add(i.getInstanceId());
}
}
return unhealthyInstances;
}
Aggregations