Search in sources :

Example 61 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class ClusterV4RequestToClusterConverterTest method testConvertClouderaManagerRequestWithNullRepo.

@Test
public void testConvertClouderaManagerRequestWithNullRepo() {
    ClusterV4Request request = new ClusterV4Request();
    request.setBlueprintName(BLUEPRINT);
    blueprint.setStackType(StackType.CDH.name());
    when(blueprintService.getByNameForWorkspaceAndLoadDefaultsIfNecessary(eq(BLUEPRINT), any())).thenReturn(blueprint);
    ClouderaManagerV4Request cm = new ClouderaManagerV4Request();
    ClouderaManagerProductV4Request cdp = new ClouderaManagerProductV4Request();
    cdp.setName("cdp");
    cdp.setParcel("cdp.parcel");
    cdp.setVersion("cdp.version");
    cdp.setCsd(List.of("cdp.csd"));
    ClouderaManagerProductV4Request cdf = new ClouderaManagerProductV4Request();
    cdf.setName("cdf");
    cdf.setParcel("cdf.parcel");
    cdf.setVersion("cdf.version");
    cdf.setCsd(List.of("cdf.csd"));
    List<ClouderaManagerProductV4Request> products = List.of(cdp, cdf);
    cm.setProducts(products);
    request.setCm(cm);
    Cluster cluster = underTest.convert(request);
    assertFalse(cluster.getComponents().isEmpty());
    assertEquals(2, cluster.getComponents().size());
    assertAll(cluster.getComponents().stream().map(component -> () -> assertEquals(ComponentType.CDH_PRODUCT_DETAILS, component.getComponentType())));
    List<Json> cdps = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdp")).collect(Collectors.toList());
    Json cdpJson = new Json(cdp);
    assertAll(() -> assertEquals(1, cdps.size()), () -> assertEquals(cdpJson, cdps.iterator().next()));
    List<Json> cdfs = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdf")).collect(Collectors.toList());
    Json cdfJson = new Json(cdf);
    assertAll(() -> assertEquals(1, cdfs.size()), () -> assertEquals(cdfJson, cdfs.iterator().next()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) GatewayConvertUtil(com.sequenceiq.cloudbreak.converter.util.GatewayConvertUtil) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) CloudStorageConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.CloudStorageConverter) GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Spy(org.mockito.Spy) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudStorageBase(com.sequenceiq.common.api.cloudstorage.CloudStorageBase) Set(java.util.Set) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) StackType(com.sequenceiq.cloudbreak.cloud.model.component.StackType) Collectors(java.util.stream.Collectors) GatewayV4RequestToGatewayConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.gateway.GatewayV4RequestToGatewayConverter) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) Matchers.is(org.hamcrest.Matchers.is) CloudStorageValidationUtil(com.sequenceiq.cloudbreak.converter.util.CloudStorageValidationUtil) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) IdBrokerConverterUtil(com.sequenceiq.cloudbreak.converter.IdBrokerConverterUtil) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) InjectMocks(org.mockito.InjectMocks) ClouderaManagerRepositoryV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.repository.ClouderaManagerRepositoryV4Request) Collections.emptySet(java.util.Collections.emptySet) ClusterV4RequestToClusterConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.ClusterV4RequestToClusterConverter) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Mockito.verify(org.mockito.Mockito.verify) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Mockito(org.mockito.Mockito) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) Test(org.junit.jupiter.api.Test)

Example 62 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class TemplateValidatorTest method setUp.

@BeforeEach
public void setUp() {
    credential = TestUtil.awsCredential();
    user = new User();
    optionalUser = Optional.of(user);
    MockitoAnnotations.initMocks(this);
    stack = TestUtil.stack(Status.AVAILABLE, credential);
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    String location = "fake location";
    VmTypeMeta.VmTypeMetaBuilder vmMetaBuilder = VmTypeMeta.VmTypeMetaBuilder.builder().withCpuAndMemory(Integer.valueOf(8), Float.valueOf(15)).withPrice(0.42).withVolumeEncryptionSupport(true).withSsdConfig(1, 17592, 1, 24);
    VmType c3VmType = VmType.vmTypeWithMeta("c3.2xlarge", vmMetaBuilder.create(), false);
    VmType i3VmType = VmType.vmTypeWithMeta("i3.2xlarge", vmMetaBuilder.withEphemeralConfig(1, 17592, 1, 24).create(), false);
    Map<String, Set<VmType>> machines = new HashMap<>();
    machines.put(location, Set.of(c3VmType, i3VmType));
    cloudVmTypes = new CloudVmTypes(machines, new HashMap<>());
    when(cloudParameterService.getVmTypesV2(isNull(), anyString(), isNull(), any(CdpResourceType.class), any(HashMap.class))).thenReturn(cloudVmTypes);
    Platform platform = Platform.platform("AWS");
    Map<Platform, Map<String, VolumeParameterType>> diskMappings = new HashMap<>();
    Map<String, VolumeParameterType> diskTypeMap = new HashMap<>();
    diskTypeMap.put("standard", VolumeParameterType.SSD);
    diskTypeMap.put(AwsDiskType.Ephemeral.value(), VolumeParameterType.EPHEMERAL);
    diskMappings.put(platform, diskTypeMap);
    platformDisks = new PlatformDisks(new HashMap<>(), new HashMap<>(), diskMappings, new HashMap<>());
    when(cloudParameterService.getDiskTypes()).thenReturn(platformDisks);
    when(locationService.location(anyString(), isNull())).thenReturn(location);
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) User(com.sequenceiq.cloudbreak.workspace.model.User) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) HashMap(java.util.HashMap) Map(java.util.Map) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 63 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class SshKeyService method createSshStateParams.

private OrchestratorStateParams createSshStateParams(Stack stack, String user, KeyPair keyPair, String authKeysComment, String saltState) {
    Cluster cluster = stack.getCluster();
    Set<Node> nodes = stackUtil.collectReachableNodes(stack);
    OrchestratorStateParams stateParams = new OrchestratorStateParams();
    stateParams.setState(saltState);
    stateParams.setPrimaryGatewayConfig(gatewayConfigService.getGatewayConfig(stack, stack.getPrimaryGatewayInstance(), stack.getCluster().hasGateway()));
    stateParams.setTargetHostNames(nodes.stream().map(Node::getHostname).collect(Collectors.toSet()));
    stateParams.setAllNodes(nodes);
    stateParams.setExitCriteriaModel(ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(stack.getId(), cluster.getId()));
    stateParams.setStateParams(createSshParams(user, keyPair, authKeysComment));
    OrchestratorStateRetryParams retryParams = new OrchestratorStateRetryParams();
    retryParams.setMaxRetry(SSH_KEY_OPERATION_RETRY_COUNT);
    stateParams.setStateRetryParams(retryParams);
    return stateParams;
}
Also used : OrchestratorStateRetryParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateRetryParams) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams)

Example 64 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class BaseLegacyStructuredFlowEventFactory method createStructuredNotificationEvent.

public StructuredNotificationEvent createStructuredNotificationEvent(Stack stack, String notificationType, String message, String instanceGroupName) {
    Long stackId = stack.getId();
    NotificationDetails notificationDetails = new NotificationDetails();
    notificationDetails.setNotificationType(notificationType);
    notificationDetails.setNotification(message);
    notificationDetails.setStackId(stackId);
    String stackName = stack.getName();
    String userName = stack.getCreator().getUserName();
    String userId = stack.getCreator().getUserId();
    try {
        notificationDetails.setCloud(stack.cloudPlatform());
        notificationDetails.setRegion(stack.getRegion());
        notificationDetails.setAvailabiltyZone(stack.getAvailabilityZone());
        notificationDetails.setStackName(stack.getDisplayName());
        notificationDetails.setStackStatus(stack.getStatus().name());
        notificationDetails.setNodeCount(stack.getNotDeletedInstanceMetaDataSet().size());
        Cluster cluster = stack.getCluster();
        notificationDetails.setInstanceGroup(instanceGroupName);
        if (cluster != null) {
            notificationDetails.setClusterId(cluster.getId());
            notificationDetails.setClusterName(cluster.getName());
            notificationDetails.setClusterStatus(stack.getStatus().name());
            Blueprint blueprint = cluster.getBlueprint();
            if (blueprint != null) {
                notificationDetails.setBlueprintId(blueprint.getId());
                notificationDetails.setBlueprintName(blueprint.getStackName());
            }
        }
    } catch (AccessDeniedException e) {
        LOGGER.info("Access denied in structured notification event creation, user: {}, stack: {}", userName, stackId, e);
    }
    String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
    OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), NOTIFICATION, resourceType, stackId, stackName, nodeConfig.getInstanceUUID(), cbVersion, stack.getWorkspace().getId(), userId, userName, stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
    return new StructuredNotificationEvent(operationDetails, notificationDetails);
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) NotificationDetails(com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)

Example 65 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class BaseLegacyStructuredFlowEventFactory method createStucturedFlowEvent.

@Override
public StructuredFlowEvent createStucturedFlowEvent(Long stackId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
    Stack stack = stackService.getByIdWithTransaction(stackId);
    String resourceType = (stack.getType() == null || stack.getType().equals(StackType.WORKLOAD)) ? CloudbreakEventService.DATAHUB_RESOURCE_TYPE : CloudbreakEventService.DATALAKE_RESOURCE_TYPE;
    OperationDetails operationDetails = new OperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stackId, stack.getName(), nodeConfig.getId(), cbVersion, stack.getWorkspace().getId(), stack.getCreator().getUserId(), stack.getCreator().getUserName(), stack.getTenant().getName(), stack.getResourceCrn(), stack.getCreator().getUserCrn(), stack.getEnvironmentCrn(), null);
    StackDetails stackDetails = null;
    ClusterDetails clusterDetails = null;
    BlueprintDetails blueprintDetails = null;
    if (detailed) {
        stackDetails = stackToStackDetailsConverter.convert(stack);
        Cluster cluster = stack.getCluster();
        if (cluster != null) {
            clusterDetails = clusterToClusterDetailsConverter.convert(cluster);
            blueprintDetails = getIfNotNull(cluster.getBlueprint(), blueprintToBlueprintDetailsConverter::convert);
        }
    }
    StructuredFlowEvent event = new StructuredFlowEvent(operationDetails, flowDetails, stackDetails, clusterDetails, blueprintDetails);
    if (exception != null) {
        event.setException(ExceptionUtils.getStackTrace(exception));
    }
    return event;
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) BlueprintDetails(com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails) ClusterDetails(com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails) StackDetails(com.sequenceiq.cloudbreak.structuredevent.event.StackDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)407 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)248 Test (org.junit.jupiter.api.Test)125 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)60 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)58 Optional (java.util.Optional)51 Test (org.junit.Test)50 List (java.util.List)49 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)47 Set (java.util.Set)43 Json (com.sequenceiq.cloudbreak.common.json.Json)39 Map (java.util.Map)39 Collectors (java.util.stream.Collectors)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)36 Inject (javax.inject.Inject)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)35