Search in sources :

Example 1 with Stack

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

the class FreeipaStructuredFlowEventFactory method createStructuredFlowEvent.

@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    Stack stack = stackService.getStackById(resourceId);
    String resourceType = CloudbreakEventService.FREEIPA_RESOURCE_TYPE;
    CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stack.getId(), stack.getName(), nodeConfig.getId(), serviceVersion, stack.getAccountId(), stack.getResourceCrn(), ThreadBasedUserCrnProvider.getUserCrn(), stack.getEnvironmentCrn(), null);
    StackStatus stackStatus = stack.getStackStatus();
    CDPStructuredFlowEvent event = new CDPStructuredFlowEvent(operationDetails, flowDetails, null, stackStatus.getDetailedStackStatus().name(), stackStatus.getStatusReason());
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : CDPStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 2 with Stack

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

the class UserSyncServiceTest method testAsyncSynchronizeUsersUsesInternalCrn.

@Test
void testAsyncSynchronizeUsersUsesInternalCrn() {
    Stack stack = mock(Stack.class);
    when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
    when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(anySet(), anyString())).thenReturn(List.of(stack));
    Operation operation = mock(Operation.class);
    when(operation.getStatus()).thenReturn(OperationState.RUNNING);
    when(operation.getOperationId()).thenReturn("operationId");
    when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
    UserSyncStatus userSyncStatus = mock(UserSyncStatus.class);
    when(userSyncStatusService.getOrCreateForStack(any(Stack.class))).thenReturn(userSyncStatus);
    when(userSyncStatusService.save(userSyncStatus)).thenReturn(userSyncStatus);
    UserSyncService spyService = spy(underTest);
    doAnswer(invocation -> {
        assertEquals(INTERNAL_ACTOR_CRN, ThreadBasedUserCrnProvider.getUserCrn());
        return null;
    }).when(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
    spyService.synchronizeUsers("accountId", "actorCrn", Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
    verify(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with Stack

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

the class CcmUserDataService method saveCcmV2Config.

private void saveCcmV2Config(Long stackId, CcmV2Parameters ccmV2Parameters) {
    String ccmV2AgentCrn = ccmV2Parameters.getAgentCrn();
    if (StringUtils.isNotBlank(ccmV2AgentCrn)) {
        LOGGER.debug("Adding CcmV2AgentCrn '{}' to stack", ccmV2AgentCrn);
        Stack stack = stackService.getStackById(stackId);
        stack.setCcmV2AgentCrn(ccmV2AgentCrn);
        stackService.save(stack);
        LOGGER.debug("Added CcmV2AgentCrn  '{}' to stack", ccmV2AgentCrn);
    }
}
Also used : Stack(com.sequenceiq.freeipa.entity.Stack)

Example 4 with Stack

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

the class FreeIpaOrchestationConfigServiceTest method testGetSaltConfig.

@Test
public void testGetSaltConfig() throws Exception {
    Stack stack = mock(Stack.class);
    FreeIpaConfigView freeIpaConfigView = mock(FreeIpaConfigView.class);
    Map freeIpaConfigViewMap = mock(Map.class);
    when(freeIpaConfigService.createFreeIpaConfigs(any(), any())).thenReturn(freeIpaConfigView);
    when(stack.getCloudPlatform()).thenReturn(CLOUD_PLATFORM);
    when(freeIpaConfigView.toMap()).thenReturn(freeIpaConfigViewMap);
    when(telemetryConfigService.createTelemetryPillarConfig(any())).thenReturn(Map.of());
    when(proxyConfigService.createProxyPillarConfig(any())).thenReturn(Map.of());
    when(tagConfigService.createTagsPillarConfig(any())).thenReturn(Map.of());
    SaltConfig saltConfig = underTest.getSaltConfig(stack, Set.of());
    Map<String, SaltPillarProperties> servicePillarConfig = saltConfig.getServicePillarConfig();
    assertNotNull(servicePillarConfig);
    SaltPillarProperties freeIpaProperties = servicePillarConfig.get("freeipa");
    assertNotNull(freeIpaProperties);
    assertEquals("/freeipa/init.sls", freeIpaProperties.getPath());
    assertEquals(freeIpaConfigViewMap, freeIpaProperties.getProperties().get("freeipa"));
    SaltPillarProperties discoveryProperties = servicePillarConfig.get("discovery");
    assertNotNull(discoveryProperties);
    assertEquals("/discovery/init.sls", discoveryProperties.getPath());
    assertEquals(CLOUD_PLATFORM, discoveryProperties.getProperties().get("platform"));
}
Also used : SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) FreeIpaConfigView(com.sequenceiq.freeipa.service.freeipa.config.FreeIpaConfigView) Map(java.util.Map) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with Stack

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

the class CreateFreeIpaRequestToStackConverter method extendGatewaySecurityGroupWithDefaultGatewayCidrs.

private void extendGatewaySecurityGroupWithDefaultGatewayCidrs(Stack stack) {
    Set<InstanceGroup> gateways = stack.getInstanceGroups().stream().filter(ig -> InstanceGroupType.MASTER == ig.getInstanceGroupType()).collect(Collectors.toSet());
    Set<String> defaultGatewayCidrs = defaultGatewayCidr.stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet());
    if (!defaultGatewayCidrs.isEmpty() && !stack.getTunnel().useCcm()) {
        for (InstanceGroup gateway : gateways) {
            if (gateway.getSecurityGroup() != null && CollectionUtils.isEmpty(gateway.getSecurityGroup().getSecurityGroupIds())) {
                Set<SecurityRule> rules = gateway.getSecurityGroup().getSecurityRules();
                defaultGatewayCidrs.forEach(cloudbreakCidr -> rules.add(createSecurityRule(gateway.getSecurityGroup(), cloudbreakCidr, stack.getGatewayport().toString())));
                LOGGER.info("The control plane cidrs {} are added to the {} gateway group for the {} port.", defaultGatewayCidrs, gateway.getGroupName(), stack.getGatewayport());
            }
        }
    }
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) GCP_KMS_ENCRYPTION_KEY(com.sequenceiq.freeipa.util.CloudArgsForIgConverter.GCP_KMS_ENCRYPTION_KEY) LoggerFactory(org.slf4j.LoggerFactory) PasswordUtil(com.sequenceiq.cloudbreak.util.PasswordUtil) TimeoutException(java.util.concurrent.TimeoutException) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) GcpResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpResourceEncryptionParameters) StringUtils(org.apache.commons.lang3.StringUtils) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) Future(java.util.concurrent.Future) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) NetworkRequestToNetworkConverter(com.sequenceiq.freeipa.converter.network.NetworkRequestToNetworkConverter) CrnService(com.sequenceiq.freeipa.util.CrnService) Tunnel(com.sequenceiq.common.api.type.Tunnel) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest) EnumMap(java.util.EnumMap) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) StringIterate.isEmpty(com.gs.collections.impl.utility.StringIterate.isEmpty) DISK_ENCRYPTION_SET_ID(com.sequenceiq.freeipa.util.CloudArgsForIgConverter.DISK_ENCRYPTION_SET_ID) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) CloudArgsForIgConverter(com.sequenceiq.freeipa.util.CloudArgsForIgConverter) StackAuthenticationRequestToStackAuthenticationConverter(com.sequenceiq.freeipa.converter.authentication.StackAuthenticationRequestToStackAuthenticationConverter) BackupConverter(com.sequenceiq.freeipa.converter.backup.BackupConverter) SecurityGroup(com.sequenceiq.freeipa.entity.SecurityGroup) Region(com.sequenceiq.cloudbreak.cloud.model.Region) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) AWS_KMS_ENCRYPTION_KEY(com.sequenceiq.freeipa.util.CloudArgsForIgConverter.AWS_KMS_ENCRYPTION_KEY) PlacementBase(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.region.PlacementBase) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) TelemetryConverter(com.sequenceiq.freeipa.converter.telemetry.TelemetryConverter) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) InstanceGroupRequestToInstanceGroupConverter(com.sequenceiq.freeipa.converter.instance.InstanceGroupRequestToInstanceGroupConverter) HashMap(java.util.HashMap) AzureResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceEncryptionParameters) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) AwsDiskEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) Platform.platform(com.sequenceiq.cloudbreak.cloud.model.Platform.platform) AccountTagService(com.sequenceiq.freeipa.service.tag.AccountTagService) InstanceGroupType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupType) Stack(com.sequenceiq.freeipa.entity.Stack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) SecurityRule(com.sequenceiq.freeipa.entity.SecurityRule) Maps(com.google.common.collect.Maps) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) CostTagging(com.sequenceiq.cloudbreak.tag.CostTagging) SecurityRule(com.sequenceiq.freeipa.entity.SecurityRule) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23