Search in sources :

Example 61 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method getFirstValidPrivateId.

private Long getFirstValidPrivateId(Iterable<InstanceGroup> instanceGroups) {
    LOGGER.info("Get first valid PrivateId of instanceGroups");
    long highest = 0;
    for (InstanceGroup instanceGroup : instanceGroups) {
        LOGGER.info("Checking of instanceGroup: {}", instanceGroup.getGroupName());
        for (InstanceMetaData metaData : instanceGroup.getAllInstanceMetaData()) {
            Long privateId = metaData.getPrivateId();
            LOGGER.info("InstanceMetaData metaData: privateId: {}, instanceGroupName: {}, instanceId: {}, status: {}", privateId, metaData.getInstanceGroupName(), metaData.getInstanceId(), metaData.getInstanceStatus());
            if (privateId == null) {
                continue;
            }
            if (privateId > highest) {
                highest = privateId;
            }
        }
    }
    LOGGER.info("highest privateId: {}", highest);
    return highest == 0 ? 0 : highest + 1;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 62 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class InstanceMetadataService method updateInstanceStatus.

public void updateInstanceStatus(Iterable<InstanceGroup> instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus newStatus, Collection<String> candidateAddresses) {
    for (InstanceGroup group : instanceGroup) {
        for (InstanceMetaData instanceMetaData : group.getInstanceMetaData()) {
            if (candidateAddresses.contains(instanceMetaData.getDiscoveryFQDN())) {
                instanceMetaData.setInstanceStatus(newStatus);
                instanceMetaDataRepository.save(instanceMetaData);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 63 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class InstanceMetadataService method updateInstanceStatus.

public void updateInstanceStatus(Iterable<InstanceGroup> instanceGroup, Map<InstanceGroupType, com.sequenceiq.cloudbreak.api.model.InstanceStatus> newStatusByGroupType) {
    for (InstanceGroup group : instanceGroup) {
        com.sequenceiq.cloudbreak.api.model.InstanceStatus newStatus = newStatusByGroupType.get(group.getInstanceGroupType());
        if (newStatus != null) {
            for (InstanceMetaData instanceMetaData : group.getInstanceMetaData()) {
                instanceMetaData.setInstanceStatus(newStatus);
                instanceMetaDataRepository.save(instanceMetaData);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 64 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class StackService method validateHostGroupAdjustment.

private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
    Blueprint blueprint = stack.getCluster().getBlueprint();
    Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
    if (!hostGroup.isPresent()) {
        throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
    }
    blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IdentityUserRole(com.sequenceiq.cloudbreak.common.model.user.IdentityUserRole) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) Component(com.sequenceiq.cloudbreak.domain.Component) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) PasswordUtil(com.sequenceiq.cloudbreak.util.PasswordUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Strings(com.google.api.client.repackaged.com.google.common.base.Strings) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) OrchestratorRepository(com.sequenceiq.cloudbreak.repository.OrchestratorRepository) AmbariClusterService(com.sequenceiq.cloudbreak.service.cluster.AmbariClusterService) TxType(javax.transaction.Transactional.TxType) StackViewRepository(com.sequenceiq.cloudbreak.repository.StackViewRepository) Transactional(javax.transaction.Transactional) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) List(java.util.List) STOPPED(com.sequenceiq.cloudbreak.api.model.Status.STOPPED) STOP_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) Optional(java.util.Optional) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) StackStatusRepository(com.sequenceiq.cloudbreak.repository.StackStatusRepository) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Service(org.springframework.stereotype.Service) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Objects.requireNonNull(java.util.Objects.requireNonNull) StackResponseDecorator(com.sequenceiq.cloudbreak.service.decorator.StackResponseDecorator) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Json(com.sequenceiq.cloudbreak.domain.json.Json) Stack(com.sequenceiq.cloudbreak.domain.Stack) Nonnull(javax.annotation.Nonnull) ConversionService(org.springframework.core.convert.ConversionService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SecurityConfigRepository(com.sequenceiq.cloudbreak.repository.SecurityConfigRepository) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) OpenSshPublicKeyValidator(com.sequenceiq.cloudbreak.service.credential.OpenSshPublicKeyValidator) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) NetworkConfigurationValidator(com.sequenceiq.cloudbreak.controller.validation.network.NetworkConfigurationValidator) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) StatusRequest(com.sequenceiq.cloudbreak.api.model.StatusRequest) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 65 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method removeInstances.

public Set<String> removeInstances(Stack stack, Set<String> instanceIds, String instanceGroup) {
    LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
    List<CloudInstance> instances = new ArrayList<>();
    InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(instanceGroup);
    for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
        if (instanceIds.contains(metaData.getInstanceId())) {
            CloudInstance cloudInstance = metadataConverter.convert(metaData);
            instances.add(cloudInstance);
        }
    }
    CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
    DownscaleStackRequest downscaleRequest = new DownscaleStackRequest(cloudContext, cloudCredential, cloudStack, resources, instances);
    LOGGER.info("Triggering downscale stack event: {}", downscaleRequest);
    eventBus.notify(downscaleRequest.selector(), eventFactory.createEvent(downscaleRequest));
    try {
        DownscaleStackResult res = downscaleRequest.await();
        LOGGER.info("Downscale stack result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to downscale the stack", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return instanceIds;
    } catch (InterruptedException e) {
        LOGGER.error("Error while downscaling the stack", e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)89 Test (org.junit.Test)32 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)27 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)24 HashSet (java.util.HashSet)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)8 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)6 Template (com.sequenceiq.cloudbreak.domain.Template)6 ArrayList (java.util.ArrayList)6 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)5 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5