Search in sources :

Example 1 with CreateResourcesRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest in project cloudbreak by hortonworks.

the class AwsVariantMigrationActions method createResources.

@Bean(name = "CREATE_RESOURCES_STATE")
public Action<?, ?> createResources() {
    return new AbstractAwsVariantMigrationAction<>(AwsVariantMigrationTriggerEvent.class) {

        @Override
        protected void doExecute(AwsVariantMigrationFlowContext context, AwsVariantMigrationTriggerEvent payload, Map<Object, Object> variables) throws Exception {
            CreateResourcesRequest request = new CreateResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), payload.getHostGroupName());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : AwsVariantMigrationTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.AwsVariantMigrationTriggerEvent) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with CreateResourcesRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest in project cloudbreak by hortonworks.

the class CreateResourcesHandlerTest method testAcceptWhenPersistSuccess.

@Test
public void testAcceptWhenPersistSuccess() throws Exception {
    ReflectionTestUtils.setField(underTest, "resourceRecreators", emptyList());
    String hostGroupName = "hostGroupName";
    CreateResourcesRequest request = new CreateResourcesRequest(cloudContext, cloudCredential, cloudStack, hostGroupName);
    Event<CreateResourcesRequest> event = new Event<>(request);
    ArgumentCaptor<Event<CreateResourcesResult>> resultCaptor = ArgumentCaptor.forClass(Event.class);
    when(cloudStack.getNetwork()).thenReturn(network);
    when(awsAuthenticator.authenticate(cloudContext, cloudCredential)).thenReturn(ac);
    when(awsContextBuilder.contextInit(cloudContext, ac, network, List.of(), true)).thenReturn(awsContext);
    underTest.accept(event);
    verify(eventBus).notify(eq("CREATERESOURCESRESULT"), resultCaptor.capture());
    Event<CreateResourcesResult> result = resultCaptor.getValue();
    Assertions.assertNotNull(result);
}
Also used : CreateResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesResult) Event(reactor.bus.Event) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) Test(org.junit.jupiter.api.Test)

Example 3 with CreateResourcesRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest in project cloudbreak by hortonworks.

the class CreateResourcesHandlerTest method testAcceptWhenPersistNotSuccess.

@Test
public void testAcceptWhenPersistNotSuccess() throws Exception {
    String hostGroupName = "hostGroupName";
    CreateResourcesRequest request = new CreateResourcesRequest(cloudContext, cloudCredential, cloudStack, hostGroupName);
    Event<CreateResourcesRequest> event = new Event<>(request);
    ArgumentCaptor<Event<CreateResourcesResult>> resultCaptor = ArgumentCaptor.forClass(Event.class);
    when(cloudStack.getNetwork()).thenReturn(network);
    when(awsAuthenticator.authenticate(cloudContext, cloudCredential)).thenReturn(ac);
    RuntimeException value = new RuntimeException();
    when(awsContextBuilder.contextInit(cloudContext, ac, network, List.of(), true)).thenThrow(value);
    underTest.accept(event);
    verify(eventBus).notify(eq("AWSVARIANTMIGRATIONFAILEDEVENT"), resultCaptor.capture());
    Event<CreateResourcesResult> result = resultCaptor.getValue();
    Assertions.assertNotNull(result);
    Assertions.assertEquals(value, result.getData().getErrorDetails());
}
Also used : CreateResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesResult) Event(reactor.bus.Event) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) Test(org.junit.jupiter.api.Test)

Example 4 with CreateResourcesRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest in project cloudbreak by hortonworks.

the class CreateResourcesHandler method accept.

@Override
public void accept(Event<CreateResourcesRequest> event) {
    LOGGER.info("Re-create the resources during the AWS migration");
    CreateResourcesRequest request = event.getData();
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudCredential cloudCredential = request.getCloudCredential();
        CloudStack cloudStack = request.getCloudStack();
        AuthenticatedContext ac = awsAuthenticator.authenticate(cloudContext, cloudCredential);
        Network network = cloudStack.getNetwork();
        AwsContext awsContext = awsContextBuilder.contextInit(cloudContext, ac, network, List.of(), true);
        for (ResourceRecreator resourceRecreator : resourceRecreators) {
            resourceRecreator.recreate(request, awsContext, ac);
        }
        CreateResourcesResult result = new CreateResourcesResult(request.getResourceId());
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        LOGGER.error("Cannot re-create the AWS security group during the variant migration", e);
        CreateResourcesResult result = new CreateResourcesResult(e.getMessage(), e, request.getResourceId());
        request.getResult().onNext(result);
        eventBus.notify(AWS_VARIANT_MIGRATION_FAILED_EVENT.event(), new Event<>(event.getHeaders(), result));
    }
}
Also used : ResourceRecreator(com.sequenceiq.cloudbreak.core.flow2.stack.migration.handler.service.ResourceRecreator) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreateResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Event(reactor.bus.Event) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)

Example 5 with CreateResourcesRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest in project cloudbreak by hortonworks.

the class SecurityGroupRecreatorServiceTest method testAcceptWhenPersistSuccess.

@Test
public void testAcceptWhenPersistSuccess() throws Exception {
    String hostGroupName = "hostGroupName";
    CreateResourcesRequest request = new CreateResourcesRequest(cloudContext, cloudCredential, cloudStack, hostGroupName);
    CloudResource cloudResource = CloudResource.builder().type(ResourceType.AWS_SECURITY_GROUP).status(CommonStatus.CREATED).name("name").params(Collections.emptyMap()).build();
    when(group.getName()).thenReturn(hostGroupName);
    when(cloudStack.getGroups()).thenReturn(List.of(group));
    when(cloudStack.getNetwork()).thenReturn(network);
    when(persistenceNotifier.notifyAllocation(any(), any())).thenReturn(resourcePersisted);
    when(awsSecurityGroupResourceBuilder.create(awsContext, ac, group, network)).thenReturn(cloudResource);
    when(awsSecurityGroupResourceBuilder.build(eq(awsContext), eq(ac), eq(group), eq(network), any(), any())).thenReturn(cloudResource);
    underTest.recreate(request, awsContext, ac);
    verify(awsSecurityGroupResourceBuilder).build(any(), any(), any(), any(), any(), any());
    verify(awsSecurityGroupResourceBuilder).create(awsContext, ac, group, network);
    verify(persistenceNotifier).notifyUpdate(cloudResource, cloudContext);
}
Also used : CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Aggregations

CreateResourcesRequest (com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest)6 Test (org.junit.jupiter.api.Test)4 CreateResourcesResult (com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesResult)3 Event (reactor.bus.Event)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 AwsContext (com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 AwsVariantMigrationTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.AwsVariantMigrationTriggerEvent)1 ResourceRecreator (com.sequenceiq.cloudbreak.core.flow2.stack.migration.handler.service.ResourceRecreator)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1