Search in sources :

Example 6 with Resource

use of com.sequenceiq.freeipa.entity.Resource 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 7 with Resource

use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.

the class CloudResourceRetrieverServiceTest method testGetByResourceReferenceShouldReturnNOTEmptyList.

@Test
public void testGetByResourceReferenceShouldReturnNOTEmptyList() {
    Resource resource = createResource();
    CloudResource cloudResource = createCloudResource();
    when(resourceService.findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID)).thenReturn(Optional.of(resource));
    when(cloudResourceConverter.convert(resource)).thenReturn(cloudResource);
    Optional<CloudResource> actual = underTest.findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID);
    assertTrue(actual.isPresent());
    assertEquals(cloudResource, actual.get());
    verify(resourceService).findByResourceReferenceAndStatusAndTypeAndStack(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE, STACK_ID);
    verify(cloudResourceConverter).convert(resource);
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 8 with Resource

use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.

the class CloudResourceRetrieverServiceTest method createResource.

private Resource createResource() {
    Resource resource = new Resource();
    resource.setResourceName(RESOURCE);
    return resource;
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.freeipa.entity.Resource)

Example 9 with Resource

use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.

the class StackProvisionActions method provisioningFinishedAction.

@Bean(name = "PROVISIONING_FINISHED_STATE")
public Action<?, ?> provisioningFinishedAction() {
    return new AbstractStackProvisionAction<>(LaunchStackResult.class) {

        @Override
        protected void doExecute(StackContext context, LaunchStackResult payload, Map<Object, Object> variables) {
            Stack stack = stackProvisionService.provisioningFinished(context, payload, variables);
            StackContext newContext = new StackContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
            List<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
            List<CloudResource> cloudResources = resources.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
            return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances, cloudInstances);
        }
    };
}
Also used : CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Date(java.util.Date) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) ValidationRequest(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationRequest) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) CreateCredentialResult(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult) Collectors(java.util.stream.Collectors) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Configuration(org.springframework.context.annotation.Configuration) SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) CreateUserDataRequest(com.sequenceiq.freeipa.flow.stack.provision.event.userdata.CreateUserDataRequest) StackFailureContext(com.sequenceiq.freeipa.flow.stack.StackFailureContext) ValidationResult(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationResult) Flow(com.sequenceiq.flow.core.Flow) SetupRequest(com.sequenceiq.cloudbreak.cloud.event.setup.SetupRequest) StackProvisionEvent(com.sequenceiq.freeipa.flow.stack.provision.StackProvisionEvent) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter) ImageService(com.sequenceiq.freeipa.service.image.ImageService) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) AbstractStackFailureAction(com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction) Inject(javax.inject.Inject) StateContext(org.springframework.statemachine.StateContext) Resource(com.sequenceiq.freeipa.entity.Resource) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreateUserDataSuccess(com.sequenceiq.freeipa.flow.stack.provision.event.userdata.CreateUserDataSuccess) StackProvisionState(com.sequenceiq.freeipa.flow.stack.provision.StackProvisionState) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) START_DATE(com.sequenceiq.freeipa.flow.stack.provision.StackProvisionConstants.START_DATE) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) LaunchStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest) Bean(org.springframework.context.annotation.Bean) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) 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 10 with Resource

use of com.sequenceiq.freeipa.entity.Resource in project cloudbreak by hortonworks.

the class AbstractStackTerminationAction method createFlowContext.

@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    List<Resource> resourceList = resourceService.findAllByStackId(stack.getId());
    List<CloudResource> resources = resourceList.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
    return new StackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources);
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) Inject(javax.inject.Inject) StackTerminationEvent(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationEvent) StateContext(org.springframework.statemachine.StateContext) Credential(com.sequenceiq.freeipa.dto.Credential) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Resource(com.sequenceiq.freeipa.entity.Resource) Location(com.sequenceiq.cloudbreak.cloud.model.Location) StackService(com.sequenceiq.freeipa.service.stack.StackService) AbstractStackAction(com.sequenceiq.freeipa.flow.stack.AbstractStackAction) Stack(com.sequenceiq.freeipa.entity.Stack) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackTerminationState(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationState) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CredentialToCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) StackTerminationContext(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) Optional(java.util.Optional) CredentialService(com.sequenceiq.freeipa.service.CredentialService) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) StackTerminationContext(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationContext) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 Resource (com.sequenceiq.freeipa.entity.Resource)14 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)7 ResourceService (com.sequenceiq.freeipa.service.resource.ResourceService)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Inject (javax.inject.Inject)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)6 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)6 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)6 Map (java.util.Map)6 Bean (org.springframework.context.annotation.Bean)6 Configuration (org.springframework.context.annotation.Configuration)6 Action (org.springframework.statemachine.action.Action)6 FlowParameters (com.sequenceiq.flow.core.FlowParameters)5 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)4 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)4 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4