Search in sources :

Example 61 with Stack

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

the class ReactorNotifier method notify.

public FlowIdentifier notify(Long stackId, String selector, Acceptable acceptable, Function<Long, Stack> getStackFn) {
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(eventParameterFactory.createEventParameters(stackId), acceptable);
    Stack stack = getStackFn.apply(event.getData().getResourceId());
    Optional.ofNullable(stack).map(Stack::getStatus).ifPresent(isTriggerAllowedInMaintenance(selector));
    reactorReporter.logInfoReport();
    reactor.notify(selector, event);
    return checkFlowStatus(event, stack.getName());
}
Also used : Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 62 with Stack

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

the class CcmKeyDeregisterAction method createRequest.

@Override
protected CcmKeyDeregisterRequest createRequest(StackTerminationContext context) {
    Stack stack = context.getStack();
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    String actorCrn = Objects.requireNonNull(userCrn, "userCrn is null");
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String keyId = CcmResourceUtil.getKeyId(stack.getResourceCrn());
    return new CcmKeyDeregisterRequest(stack.getId(), actorCrn, accountId, keyId, stack.getTunnel());
}
Also used : CcmKeyDeregisterRequest(com.sequenceiq.cloudbreak.reactor.api.event.recipe.CcmKeyDeregisterRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 63 with Stack

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

the class StackUpscaleActions method finishExtendMetadata.

@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
    return new AbstractStackUpscaleAction<>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) throws TransactionExecutionException {
            Integer adjustment = context.getHostGroupWithAdjustment().values().stream().reduce(0, Integer::sum);
            Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), adjustment, payload);
            variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
            Set<String> hostGroups = context.getHostGroupWithAdjustment().keySet();
            List<InstanceGroup> scaledInstanceGroups = instanceGroupService.findByStackIdAndInstanceGroupNames(payload.getResourceId(), hostGroups);
            boolean gatewayWasUpscaled = scaledInstanceGroups.stream().anyMatch(instanceGroup -> InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()));
            if (gatewayWasUpscaled) {
                LOGGER.info("Gateway type instance group");
                Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
                InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
                if (null == gatewayMetaData) {
                    throw new CloudbreakServiceException("Could not get gateway instance metadata from the cloud provider.");
                }
                DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
                CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
                LOGGER.info("Send GetSSHFingerprintsRequest because we need to collect SSH fingerprints");
                Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
                sendEvent(context, sshFingerPrintReq);
            } else {
                StackEvent bootstrapPayload = new StackEvent(context.getStack().getId());
                sendEvent(context, StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
            }
        }
    };
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Map(java.util.Map) HashMap(java.util.HashMap) Bean(org.springframework.context.annotation.Bean)

Example 64 with Stack

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

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<>(UpscaleStackValidationResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, UpscaleStackValidationResult payload, Map<Object, Object> variables) {
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
            Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), true, context.isRepair(), context.getStackNetworkScaleDetails());
            List<CloudResource> resources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
            CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
            AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = context.getAdjustmentTypeWithThreshold();
            if (adjustmentTypeWithThreshold == null) {
                Integer exactNumber = hostGroupWithInstanceCountToCreate.values().stream().reduce(0, Integer::sum);
                adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, exactNumber.longValue());
            }
            LOGGER.info("Adjustment type with threshold for upscale request: {}", adjustmentTypeWithThreshold);
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, resources, adjustmentTypeWithThreshold);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) BootstrapNewNodesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesResult) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) HOST_GROUP_WITH_HOSTNAMES(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_HOSTNAMES) Collectors(java.util.stream.Collectors) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExtendHostMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataRequest) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) BootstrapNewNodesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) HOST_GROUP_WITH_ADJUSTMENT(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Logger(org.slf4j.Logger) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyReRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyReRegistrationRequest) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Map(java.util.Map) HashMap(java.util.HashMap) Bean(org.springframework.context.annotation.Bean)

Example 65 with Stack

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

the class ClusterCredentialChangeHandler method accept.

@Override
public void accept(Event<ClusterCredentialChangeRequest> event) {
    ClusterCredentialChangeRequest request = event.getData();
    ClusterCredentialChangeResult result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        ClusterSecurityService clusterSecurityService = clusterApiConnectors.getConnector(stack).clusterSecurityService();
        switch(request.getType()) {
            case REPLACE:
                clusterSecurityService.replaceUserNamePassword(request.getUser(), request.getPassword());
                break;
            case UPDATE:
                clusterSecurityService.updateUserNamePassword(request.getPassword());
                break;
            default:
                throw new UnsupportedOperationException("Ambari credential update request not supported: " + request.getType());
        }
        result = new ClusterCredentialChangeResult(request);
    } catch (Exception e) {
        result = new ClusterCredentialChangeResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : ClusterCredentialChangeRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest) ClusterCredentialChangeResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeResult) ClusterSecurityService(com.sequenceiq.cloudbreak.cluster.api.ClusterSecurityService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67