Search in sources :

Example 11 with InstanceMetaData

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);
    }
}
Also used : SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TrustManager(javax.net.ssl.TrustManager) SavingX509TrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager.SavingX509TrustManager) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) SavingX509TrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager.SavingX509TrustManager) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 12 with InstanceMetaData

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);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Logger(org.slf4j.Logger) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) Service(org.springframework.stereotype.Service) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Stack(com.sequenceiq.cloudbreak.domain.Stack) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 13 with InstanceMetaData

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);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 14 with InstanceMetaData

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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) Map(java.util.Map) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashSet(java.util.HashSet)

Example 15 with InstanceMetaData

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;
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Location(com.sequenceiq.cloudbreak.cloud.model.Location) HashSet(java.util.HashSet)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)71 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)24 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)17 Map (java.util.Map)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)13 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)11 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 List (java.util.List)9 Set (java.util.Set)9 Inject (javax.inject.Inject)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Matchers.anyString (org.mockito.Matchers.anyString)7