Search in sources :

Example 26 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class StackProvisionService method setupTls.

public void setupTls(StackContext context) throws CloudbreakException {
    Stack stack = context.getStack();
    Set<InstanceMetaData> instanceMetaDataSet = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getAllInstanceMetaData().stream()).collect(Collectors.toSet());
    for (InstanceMetaData gwInstance : instanceMetaDataSet) {
        tlsSetupService.setupTls(stack.getId(), gwInstance);
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ImageService(com.sequenceiq.freeipa.service.image.ImageService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) ErrorHandlerAwareReactorEventFactory(com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory) Inject(javax.inject.Inject) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) TlsSetupService(com.sequenceiq.freeipa.service.TlsSetupService) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Set(java.util.Set) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) EventBus(reactor.bus.EventBus) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DateUtils(org.apache.commons.lang3.time.DateUtils) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) List(java.util.List) Component(org.springframework.stereotype.Component) OperationException(com.sequenceiq.cloudbreak.service.OperationException) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) MetadataSetupService(com.sequenceiq.freeipa.service.stack.instance.MetadataSetupService) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackUpdater(com.sequenceiq.freeipa.service.stack.StackUpdater) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 27 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class ImageChangeActions method setImageOnProvider.

@Bean(name = "SET_IMAGE_ON_PROVIDER_STATE")
public AbstractImageChangeAction<?> setImageOnProvider() {
    return new AbstractImageChangeAction<>(StackEvent.class) {

        @Inject
        private ResourceService resourceService;

        @Inject
        private ResourceToCloudResourceConverter cloudResourceConverter;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
            CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
            Collection<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
            List<CloudResource> cloudResources = resources.stream().map(resource -> cloudResourceConverter.convert(resource)).collect(Collectors.toList());
            UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
            sendEvent(context, request);
        }

        @Override
        protected Object getFailurePayload(StackEvent payload, Optional<StackContext> flowContext, Exception ex) {
            LOGGER.error("[SET_IMAGE_ON_PROVIDER_STATE] failed", ex);
            return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) IMAGE_CHANGE_FAILED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FAILED_EVENT) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) IMAGE_CHANGE_FINISHED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FINISHED_EVENT) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Logger(org.slf4j.Logger) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudPlatformResult(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult) List(java.util.List) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 28 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class ImageChangeActions method prepareImage.

@Bean(name = "PREPARE_IMAGE_STATE")
public AbstractImageChangeAction<?> prepareImage() {
    return new AbstractImageChangeAction<>(ImageChangeEvent.class) {

        @Inject
        private ImageConverter imageConverter;

        @Inject
        private ImageService imageService;

        @Override
        protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
            CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
            Image image = imageConverter.convert(imageService.getByStack(context.getStack()));
            PrepareImageRequest<Object> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
            LOGGER.info("Prepare image: {}", image);
            sendEvent(context, request);
        }

        @Override
        protected Object getFailurePayload(ImageChangeEvent payload, Optional<StackContext> flowContext, Exception ex) {
            LOGGER.error("[PREPARE_IMAGE_STATE] failed", ex);
            return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
        }
    };
}
Also used : Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Example 29 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class ImageChangeActionTest method testSameImage.

@Test
public void testSameImage() throws Exception {
    StackContext stackContext = mock(StackContext.class);
    Stack stack = new Stack();
    when(stackContext.getStack()).thenReturn(stack);
    when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
    ImageEntity imageEntity = new ImageEntity();
    imageEntity.setId(2L);
    ImageSettingsRequest request = new ImageSettingsRequest();
    when(imageService.getByStackId(1L)).thenReturn(imageEntity);
    when(imageService.changeImage(stack, request)).thenReturn(imageEntity);
    when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of());
    Map<Object, Object> variables = new HashMap<>();
    underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
    assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
    assertFalse(variables.containsKey(ORIGINAL_IMAGE_REVISION));
    assertFalse(variables.containsKey(IMAGE_ENTITY_ID));
    assertEquals(imageEntity, variables.get(ORIGINAL_IMAGE));
    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
    ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
    assertEquals(IMAGE_CHANGE_NOT_REQUIRED_EVENT.event(), event.selector());
    assertEquals(1L, event.getResourceId());
    assertEquals(request, event.getRequest());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) HashMap(java.util.HashMap) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 30 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class ImageChangeActionTest method testStoreRevision.

@Test
public void testStoreRevision() throws Exception {
    StackContext stackContext = mock(StackContext.class);
    Stack stack = new Stack();
    when(stackContext.getStack()).thenReturn(stack);
    when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
    ImageEntity imageEntity = new ImageEntity();
    imageEntity.setId(2L);
    when(imageService.getByStackId(1L)).thenReturn(imageEntity);
    when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of(1, 2, 3));
    Map<Object, Object> variables = new HashMap<>();
    ImageSettingsRequest request = new ImageSettingsRequest();
    underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
    assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
    assertEquals(3, variables.get(ORIGINAL_IMAGE_REVISION));
    assertEquals(2L, variables.get(IMAGE_ENTITY_ID));
    assertFalse(variables.containsKey(ORIGINAL_IMAGE));
    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
    ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
    assertEquals(IMAGE_CHANGED_IN_DB_EVENT.event(), event.selector());
    assertEquals(1L, event.getResourceId());
    assertEquals(request, event.getRequest());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) HashMap(java.util.HashMap) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)57 Map (java.util.Map)49 Bean (org.springframework.context.annotation.Bean)48 Stack (com.sequenceiq.freeipa.entity.Stack)45 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)30 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)30 FlowParameters (com.sequenceiq.flow.core.FlowParameters)11 List (java.util.List)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 Collectors (java.util.stream.Collectors)9 Inject (javax.inject.Inject)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Flow (com.sequenceiq.flow.core.Flow)8 Configuration (org.springframework.context.annotation.Configuration)8 Action (org.springframework.statemachine.action.Action)8