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));
}
}
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);
}
}
};
}
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);
}
}
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);
}
};
}
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());
}
Aggregations