Search in sources :

Example 1 with CollectMetadataResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult 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 CollectMetadataResult

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

the class StackUpscaleActions method finishExtendMetadata.

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

        @Override
        protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), context.getInstanceGroupName(), payload);
            variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
            InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(payload.getStackId(), context.getInstanceGroupName());
            if (InstanceGroupType.GATEWAY == ig.getInstanceGroupType()) {
                InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
                CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
                Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
                sendEvent(context.getFlowId(), sshFingerPrintReq);
            } else {
                BootstrapNewNodesEvent bootstrapPayload = new BootstrapNewNodesEvent(context.getStack().getId(), upscaleCandidateAddresses);
                sendEvent(context.getFlowId(), StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
            }
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 3 with CollectMetadataResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult 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 4 with CollectMetadataResult

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

the class StackCreationActions method collectMetadataAction.

@Bean(name = "COLLECTMETADATA_STATE")
public Action<?, ?> collectMetadataAction() {
    return new AbstractStackCreationAction<CollectMetadataResult>(CollectMetadataResult.class) {

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

        @Override
        protected Selectable createRequest(StackContext context) {
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            return new GetTlsInfoRequest<GetTlsInfoResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack);
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) Bean(org.springframework.context.annotation.Bean)

Example 5 with CollectMetadataResult

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

the class CollectMetadataComponentTest method testCollectMetadata.

@Test
public void testCollectMetadata() {
    CollectMetadataResult result = sendCloudRequest();
    assertEquals(1, result.getResults().size());
    assertEquals(InstanceStatus.IN_PROGRESS, result.getResults().get(0).getCloudVmInstanceStatus().getStatus());
    assertNull(result.getErrorDetails());
}
Also used : CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) Test(org.junit.Test)

Aggregations

CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)5 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)1 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)1 GetTlsInfoRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)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 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1