Search in sources :

Example 1 with CollectMetadataRequest

use of com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest in project cloudbreak by hortonworks.

the class CollectMetadataHandler method accept.

@Override
public void accept(Event<CollectMetadataRequest> collectMetadataRequestEvent) {
    LOGGER.info("Received event: {}", collectMetadataRequestEvent);
    CollectMetadataRequest request = collectMetadataRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        List<CloudVmMetaDataStatus> instanceStatuses = connector.metadata().collect(ac, request.getCloudResource(), request.getVms());
        CollectMetadataResult collectMetadataResult = new CollectMetadataResult(request, instanceStatuses);
        request.getResult().onNext(collectMetadataResult);
        eventBus.notify(collectMetadataResult.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), collectMetadataResult));
        LOGGER.info("Metadata collection successfully finished");
    } catch (RuntimeException e) {
        CollectMetadataResult failure = new CollectMetadataResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), failure));
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)

Example 2 with CollectMetadataRequest

use of com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest in project cloudbreak by hortonworks.

the class ServiceProviderMetadataAdapter method collectMetadata.

public List<CloudVmMetaDataStatus> collectMetadata(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<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(stack);
    List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
    CollectMetadataRequest cmr = new CollectMetadataRequest(cloudContext, cloudCredential, cloudResources, cloudInstances);
    LOGGER.info("Triggering event: {}", cmr);
    eventBus.notify(CloudPlatformRequest.selector(CollectMetadataRequest.class), eventFactory.createEvent(cmr));
    try {
        CollectMetadataResult res = cmr.await();
        LOGGER.info("Result: {}", res);
        if (res.getErrorDetails() != null) {
            LOGGER.error("Failed to collect metadata", res.getErrorDetails());
            return Collections.emptyList();
        }
        return res.getResults();
    } catch (InterruptedException e) {
        LOGGER.error(format("Error while executing collectMetadata, stack: %s", cloudContext), e);
        throw new OperationException(e);
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 3 with CollectMetadataRequest

use of com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest in project cloudbreak by hortonworks.

the class StackCreationActions method provisioningFinishedAction.

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

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

        @Override
        protected Selectable createRequest(StackContext context) {
            List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
            List<CloudResource> cloudResources = cloudResourceConverter.convert(context.getStack().getResources());
            return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
        }
    };
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)3 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 LaunchStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1