Search in sources :

Example 51 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class AbstractStackStopAction method createFlowContext.

@Override
protected StackStopContext createFlowContext(FlowParameters flowParameters, StateContext<StackStopState, StackStopEvent> stateContext, P payload) {
    Long stackId = payload.getResourceId();
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    MDCBuilder.buildMdcContext(stack);
    List<InstanceMetaData> instances = new ArrayList<>(instanceMetaDataService.findNotTerminatedForStack(stackId));
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    return new StackStopContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) StackStopContext(com.sequenceiq.freeipa.flow.stack.stop.StackStopContext) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 52 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class ClusterProxyRegistrationHandler method accept.

@Override
public void accept(Event<ClusterProxyRegistrationRequest> event) {
    ClusterProxyRegistrationRequest request = event.getData();
    try {
        Set<InstanceMetaData> ims = instanceMetaDataService.findNotTerminatedForStack(request.getResourceId());
        if (ims.isEmpty()) {
            LOGGER.error("Cluster Proxy registration has failed. No available instances  found for FreeIPA");
            ClusterProxyRegistrationFailed response = new ClusterProxyRegistrationFailed(request.getResourceId(), new NotFoundException("Cluster Proxy registration has failed. No available instances  found for FreeIPA"));
            sendEvent(response, event);
        } else {
            boolean allInstanceHasFqdn = ims.stream().allMatch(im -> StringUtils.isNotBlank(im.getDiscoveryFQDN()));
            if (allInstanceHasFqdn) {
                LOGGER.info("All instances already have FQDN set, register all to cluster proxy");
                clusterProxyService.registerFreeIpa(request.getResourceId());
            } else {
                LOGGER.info("Instances missing FQDN, fallback to PGW registration");
                clusterProxyService.registerFreeIpaForBootstrap(request.getResourceId());
            }
            sendEvent(new ClusterProxyRegistrationSuccess(request.getResourceId()), event);
        }
    } catch (Exception e) {
        LOGGER.error("Cluster Proxy bootstrap registration has failed", e);
        sendEvent(new ClusterProxyRegistrationFailed(request.getResourceId(), e), event);
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ClusterProxyRegistrationFailed(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ClusterProxyRegistrationSuccess(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationSuccess) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 53 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class TelemetryAgentServiceTest method createInstanceMetadataSet.

private Set<InstanceMetaData> createInstanceMetadataSet() {
    Set<InstanceMetaData> instanceMetaDataSet = new HashSet<>();
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setId(1L);
    InstanceGroup instanceGroup = new InstanceGroup();
    Template template = new Template();
    instanceGroup.setTemplate(template);
    instanceMetaData.setInstanceGroup(instanceGroup);
    instanceMetaDataSet.add(instanceMetaData);
    return instanceMetaDataSet;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template)

Example 54 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class KerberosConfigRegisterServiceTest method testRegister.

@Test
void testRegister() {
    Stack stack = new Stack();
    stack.setEnvironmentCrn("env");
    stack.setAccountId("acc");
    stack.setName("name");
    stack.setAppVersion("2.20.0");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("fqdn");
    instanceMetaData.setPrivateIp("1.1.1.1");
    instanceGroup.setInstanceMetaData(Collections.singleton(instanceMetaData));
    stack.setInstanceGroups(Collections.singleton(instanceGroup));
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("testdomain.local");
    freeIpa.setAdminPassword("asdf");
    when(freeIpaService.findByStackId(anyLong())).thenReturn(freeIpa);
    when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
    underTest.register(1L);
    ArgumentCaptor<KerberosConfig> kerberosConfigArgumentCaptor = ArgumentCaptor.forClass(KerberosConfig.class);
    ArgumentCaptor<String> accountIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(kerberosConfigService).createKerberosConfig(kerberosConfigArgumentCaptor.capture(), accountIdArgumentCaptor.capture());
    assertEquals(stack.getAccountId(), accountIdArgumentCaptor.getValue());
    KerberosConfig kerberosConfig = kerberosConfigArgumentCaptor.getValue();
    assertEquals(stack.getName(), kerberosConfig.getName());
    assertEquals(stack.getEnvironmentCrn(), kerberosConfig.getEnvironmentCrn());
    assertEquals("kdc.testdomain.local", kerberosConfig.getUrl());
    assertEquals("kerberos.testdomain.local", kerberosConfig.getAdminUrl());
    assertEquals(instanceMetaData.getPrivateIp(), kerberosConfig.getNameServers());
    assertEquals(freeIpa.getAdminPassword(), kerberosConfig.getPassword());
    assertEquals(freeIpa.getDomain(), kerberosConfig.getDomain());
    assertEquals(freeIpa.getDomain().toUpperCase(), kerberosConfig.getRealm());
    assertEquals(KerberosType.FREEIPA, kerberosConfig.getType());
    assertEquals(KerberosConfigRegisterService.FREEIPA_DEFAULT_ADMIN, kerberosConfig.getPrincipal());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 55 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class KerberosConfigUpdateServiceTest method testUpdateNameservers.

@Test
void testUpdateNameservers() {
    Stack stack = new Stack();
    stack.setEnvironmentCrn("env");
    stack.setAccountId("acc");
    stack.setName("name");
    stack.setAppVersion("2.20.0");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData1 = new InstanceMetaData();
    instanceMetaData1.setDiscoveryFQDN("fqdn");
    instanceMetaData1.setPrivateIp("1.1.1.1");
    InstanceMetaData instanceMetaData2 = new InstanceMetaData();
    instanceMetaData2.setDiscoveryFQDN("fqdn");
    instanceMetaData2.setPrivateIp("2.2.2.2");
    instanceGroup.setInstanceMetaData(Set.of(instanceMetaData1, instanceMetaData2));
    stack.setInstanceGroups(Collections.singleton(instanceGroup));
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    KerberosConfig kerberosConfig1 = mock(KerberosConfig.class);
    KerberosConfig kerberosConfig2 = mock(KerberosConfig.class);
    List<KerberosConfig> kerberosConfigs = List.of(kerberosConfig1, kerberosConfig2);
    when(kerberosConfigService.findAllInEnvironment(any())).thenReturn(kerberosConfigs);
    underTest.updateNameservers(1L);
    ArgumentCaptor<String> nameServersCaptor = ArgumentCaptor.forClass(String.class);
    verify(kerberosConfig1).setNameServers(nameServersCaptor.capture());
    verify(kerberosConfig2).setNameServers(nameServersCaptor.capture());
    List.of(nameServersCaptor.getValue(), nameServersCaptor.getValue()).forEach(actualNameServersValue -> {
        assertTrue("1.1.1.1,2.2.2.2".equals(actualNameServersValue) || "2.2.2.2,1.1.1.1".equals(actualNameServersValue));
    });
    verify(kerberosConfigService).saveAll(eq(kerberosConfigs));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9