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);
}
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);
}
}
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;
}
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());
}
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));
}
Aggregations