Search in sources :

Example 1 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class StackDecorator method prepareInstanceGroups.

private void prepareInstanceGroups(Stack subject, StackV4Request request, Credential credential, User user, DetailedEnvironmentResponse environment) {
    Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(extendedCloudCredentialConverter.convert(credential), getInstanceGroupParameterRequests(subject));
    CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
    subject.getInstanceGroups().parallelStream().forEach(instanceGroup -> {
        subject.getCluster().getHostGroups().stream().filter(hostGroup -> hostGroup.getName().equals(instanceGroup.getGroupName())).forEach(hostGroup -> hostGroup.setInstanceGroup(instanceGroup));
        legacyRestRequestThreadLocalService.setCloudbreakUser(cloudbreakUser);
        updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
        if (instanceGroup.getTemplate() != null) {
            Template template = instanceGroup.getTemplate();
            if (template.getId() == null) {
                template.setCloudPlatform(credential.cloudPlatform());
                PlacementSettingsV4Request placement = request.getPlacement();
                String availabilityZone = placement != null ? placement.getAvailabilityZone() : subject.getAvailabilityZone();
                String region = placement != null ? placement.getRegion() : subject.getRegion();
                CdpResourceType cdpResourceType = cdpResourceTypeProvider.fromStackType(request.getType());
                template = templateDecorator.decorate(credential, template, region, availabilityZone, subject.getPlatformVariant(), cdpResourceType);
                template.setWorkspace(subject.getWorkspace());
                setupDatabaseAttachedVolume(subject, instanceGroup, template);
                template = templateService.create(user, template);
                instanceGroup.setTemplate(template);
            }
        }
        if (instanceGroup.getSecurityGroup() != null) {
            SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
            if (securityGroup.getId() == null) {
                securityGroup.setCloudPlatform(credential.cloudPlatform());
                securityGroup.setWorkspace(subject.getWorkspace());
                securityGroup = securityGroupService.create(user, securityGroup);
                instanceGroup.setSecurityGroup(securityGroup);
            }
        }
        if (instanceGroup.getInstanceGroupNetwork() != null) {
            InstanceGroupNetwork ign = instanceGroup.getInstanceGroupNetwork();
            instanceGroup.setAvailabilityZones(getAvailabilityZoneFromEnv(instanceGroup, environment));
            if (ign.getId() == null) {
                ign.setCloudPlatform(credential.cloudPlatform());
                ign = instanceGroupNetworkService.create(ign);
                instanceGroup.setInstanceGroupNetwork(ign);
            }
        }
    });
}
Also used : InstanceGroupToInstanceGroupParameterRequestConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.instancegroup.InstanceGroupToInstanceGroupParameterRequestConverter) ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) LoggerFactory(org.slf4j.LoggerFactory) Measure(com.sequenceiq.cloudbreak.aspect.Measure) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) EmbeddedDatabaseService(com.sequenceiq.cloudbreak.service.cluster.EmbeddedDatabaseService) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialToExtendedCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToExtendedCloudCredentialConverter) NetworkService(com.sequenceiq.cloudbreak.service.network.NetworkService) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) VolumeUsageType(com.sequenceiq.cloudbreak.domain.VolumeUsageType) CredentialConverter(com.sequenceiq.cloudbreak.service.environment.credential.CredentialConverter) SharedServiceValidator(com.sequenceiq.cloudbreak.service.stack.SharedServiceValidator) PlatformOrchestrators(com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Set(java.util.Set) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) EmbeddedDatabaseConfig(com.sequenceiq.cloudbreak.conf.EmbeddedDatabaseConfig) TemplateService(com.sequenceiq.cloudbreak.service.template.TemplateService) Optional(java.util.Optional) LegacyRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.LegacyRestRequestThreadLocalService) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) SecurityGroupService(com.sequenceiq.cloudbreak.service.securitygroup.SecurityGroupService) Network(com.sequenceiq.cloudbreak.domain.Network) CdpResourceTypeProvider(com.sequenceiq.cloudbreak.service.CdpResourceTypeProvider) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Orchestrator(com.sequenceiq.cloudbreak.cloud.model.Orchestrator) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroupNetworkService(com.sequenceiq.cloudbreak.service.network.instancegroup.InstanceGroupNetworkService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Nonnull(javax.annotation.Nonnull) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) InstanceGroupParameterRequest(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterRequest) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) CloudParameterService(com.sequenceiq.cloudbreak.cloud.service.CloudParameterService) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) CloudParameterCache(com.sequenceiq.cloudbreak.service.stack.CloudParameterCache) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 2 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzValidatorTest method instanceGroupNetwork.

private InstanceGroupNetwork instanceGroupNetwork(Set<String> subnetIds) {
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    Map<String, Object> map = new HashMap<>();
    map.put(NetworkConstants.SUBNET_IDS, subnetIds);
    instanceGroupNetwork.setAttributes(new Json(map));
    return instanceGroupNetwork;
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)

Example 3 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzValidatorTest method testNotSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnFalse.

@Test
public void testNotSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnFalse() {
    InstanceGroup instanceGroup = new InstanceGroup();
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setCloudPlatform(CloudPlatform.AZURE.name());
    instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    boolean supported = underTest.supportedForInstanceMetadataGeneration(instanceGroup);
    assertEquals(false, supported);
}
Also used : InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzValidatorTest method testSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnTrue.

@Test
public void testSupportedForInstanceMetadataGenerationWhenPlatformSupportedShouldReturnTrue() {
    InstanceGroup instanceGroup = new InstanceGroup();
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setCloudPlatform(CloudPlatform.AWS.name());
    instanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    boolean supported = underTest.supportedForInstanceMetadataGeneration(instanceGroup);
    assertEquals(true, supported);
}
Also used : InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceGroupNetwork

use of com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork in project cloudbreak by hortonworks.

the class MultiAzCalculatorService method collectSubnetIds.

private Set<String> collectSubnetIds(InstanceGroup instanceGroup, NetworkScaleDetails networkScaleDetails) {
    Set<String> allSubnetIds = new HashSet<>();
    InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
    if (instanceGroupNetwork != null) {
        Json attributes = instanceGroupNetwork.getAttributes();
        if (attributes != null) {
            List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(SUBNET_IDS, new ArrayList<>());
            if (isPreferredSubnetsSpecifiedForScaling(networkScaleDetails)) {
                List<String> preferredSubnetIds = networkScaleDetails.getPreferredSubnetIds();
                String preferredSubnetIdList = String.join(",", preferredSubnetIds);
                LOGGER.debug("Collect subnet ids considering the customer preferred subnet ids: {}", preferredSubnetIdList);
                Set<String> subnetIdsMatchedWithPreferred = subnetIds.stream().filter(preferredSubnetIds::contains).collect(Collectors.toSet());
                LOGGER.info("Filtered subnet id list '{}' based on the customer preferred subnet id list '{}'", String.join(",", subnetIdsMatchedWithPreferred), preferredSubnetIdList);
                allSubnetIds.addAll(subnetIdsMatchedWithPreferred);
            } else {
                allSubnetIds.addAll(subnetIds);
            }
        }
    }
    return allSubnetIds;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) HashSet(java.util.HashSet)

Aggregations

InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)13 Json (com.sequenceiq.cloudbreak.common.json.Json)8 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)8 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 HashSet (java.util.HashSet)3 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 PlacementSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request)1 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)1 InstanceGroupNetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request)1 SecurityGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)1 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)1 Measure (com.sequenceiq.cloudbreak.aspect.Measure)1