Search in sources :

Example 16 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class ComputeResourceService method stopStart.

private List<CloudVmInstanceStatus> stopStart(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Iterable<CloudInstance> instances) {
    List<CloudVmInstanceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudVmInstanceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    if (!context.isBuild()) {
        Collections.reverse(builders);
    }
    for (ComputeResourceBuilder builder : builders) {
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            CloudInstance instance = getCloudInstance(cloudResource, instances);
            if (instance != null) {
                ResourceStopStartThread thread = createThread(ResourceStopStartThread.NAME, context, auth, cloudResource, instance, builder);
                Future<ResourceRequestResult<List<CloudVmInstanceStatus>>> future = resourceBuilderExecutor.submit(thread);
                futures.add(future);
                if (isRequestFull(futures.size(), context)) {
                    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
                }
            } else {
                break;
            }
        }
    }
    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 17 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class ComputeResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, boolean cancellable) {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    int numberOfBuilders = builders.size();
    for (int i = numberOfBuilders - 1; i >= 0; i--) {
        ComputeResourceBuilder builder = builders.get(i);
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, context, auth, cloudResource, builder, cancellable);
            Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
            futures.add(future);
            if (isRequestFull(futures.size(), context)) {
                results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
            }
        }
        // wait for builder type to finish before starting the next one
        results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    }
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) ArrayList(java.util.ArrayList) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 18 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class CloudPlatformConnectors method cloudPlatformConnectors.

@PostConstruct
public void cloudPlatformConnectors() {
    platformToVariants = HashMultimap.create();
    for (CloudConnector connector : cloudConnectors) {
        map.put(new CloudPlatformVariant(connector.platform(), connector.variant()), connector);
        platformToVariants.put(connector.platform(), connector.variant());
    }
    Map<Platform, Variant> environmentDefaults = extractEnvironmentDefaultVariants();
    setupDefaultVariants(platformToVariants, environmentDefaults);
    LOGGER.debug(map.toString());
    LOGGER.debug(defaultVariants.toString());
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) PostConstruct(javax.annotation.PostConstruct)

Example 19 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class PlatformParametersHandler method accept.

@Override
public void accept(Event<PlatformParametersRequest> platformParameterRequestEvent) {
    LOGGER.info("Received event: {}", platformParameterRequestEvent);
    PlatformParametersRequest request = platformParameterRequestEvent.getData();
    Map<Platform, PlatformParameters> platformParameters = new HashMap<>();
    try {
        for (Entry<Platform, Collection<Variant>> connector : cloudPlatformConnectors.getPlatformVariants().getPlatformToVariants().entrySet()) {
            platformParameters.put(connector.getKey(), cloudPlatformConnectors.getDefault(connector.getKey()).parameters());
        }
        PlatformParametersResult platformParameterResult = new PlatformParametersResult(request, platformParameters);
        request.getResult().onNext(platformParameterResult);
        LOGGER.info("Query platform parameters finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new PlatformParametersResult(e.getMessage(), e, request));
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformParametersRequest(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParametersRequest) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) Collection(java.util.Collection) PlatformParametersResult(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParametersResult)

Example 20 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class CloudResourceAdvisor method createForBlueprint.

public PlatformRecommendation createForBlueprint(String blueprintName, Long blueprintId, PlatformResourceRequest resourceRequest, IdentityUser cbUser) {
    String cloudPlatform = resourceRequest.getCloudPlatform();
    String region = resourceRequest.getRegion();
    String availabilityZone = resourceRequest.getAvailabilityZone();
    Map<String, VmType> vmTypesByHostGroup = new HashMap<>();
    Map<String, Boolean> hostGroupContainsMasterComp = new HashMap<>();
    LOGGER.info("Advising resources for blueprintId: {}, blueprintName: {}, provider: {} and region: {}.", blueprintId, blueprintName, cloudPlatform, region);
    String blueprintText = getBlueprint(blueprintName, blueprintId, cbUser).getBlueprintText();
    Map<String, Set<String>> componentsByHostGroup = blueprintProcessorFactory.get(blueprintText).getComponentsByHostGroup();
    componentsByHostGroup.forEach((hGName, components) -> hostGroupContainsMasterComp.put(hGName, isThereMasterComponents(components)));
    CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(resourceRequest.getCredential(), resourceRequest.getRegion(), resourceRequest.getPlatformVariant(), resourceRequest.getFilters());
    VmType defaultVmType = getDefaultVmType(availabilityZone, vmTypes);
    if (defaultVmType != null) {
        componentsByHostGroup.keySet().forEach(comp -> vmTypesByHostGroup.put(comp, defaultVmType));
    }
    VmRecommendations recommendations = cloudParameterService.getRecommendation(cloudPlatform);
    Set<VmType> availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
    if (availableVmTypes == null) {
        availableVmTypes = Collections.emptySet();
    }
    if (recommendations != null) {
        Map<String, VmType> masterVmTypes = getVmTypesForComponentType(true, recommendations.getMaster(), hostGroupContainsMasterComp, availableVmTypes);
        vmTypesByHostGroup.putAll(masterVmTypes);
        Map<String, VmType> workerVmTypes = getVmTypesForComponentType(false, recommendations.getWorker(), hostGroupContainsMasterComp, availableVmTypes);
        vmTypesByHostGroup.putAll(workerVmTypes);
    }
    PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
    Platform platform = platform(cloudPlatform);
    DiskTypes diskTypes = new DiskTypes(platformDisks.getDiskTypes().get(platform), platformDisks.getDefaultDisks().get(platform), platformDisks.getDiskMappings().get(platform), platformDisks.getDiskDisplayNames().get(platform));
    return new PlatformRecommendation(vmTypesByHostGroup, availableVmTypes, diskTypes);
}
Also used : Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmRecommendations(com.sequenceiq.cloudbreak.cloud.model.VmRecommendations) DiskTypes(com.sequenceiq.cloudbreak.cloud.model.DiskTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)

Aggregations

Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)26 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)7 Map (java.util.Map)7 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)6 HashMap (java.util.HashMap)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)5 Collection (java.util.Collection)5 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)4 Set (java.util.Set)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 SpecialParameters (com.sequenceiq.cloudbreak.api.model.SpecialParameters)2 SpecialParametersJson (com.sequenceiq.cloudbreak.api.model.SpecialParametersJson)2 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)2 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)2 PlatformOrchestrators (com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2