use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class PrepareImageHandler method accept.
@Override
public void accept(Event<PrepareImageRequest> event) {
LOGGER.info("Received event: {}", event);
PrepareImageRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
Image image = request.getImage();
CloudStack stack = request.getStack();
connector.setup().prepareImage(auth, stack, image);
PrepareImageResult result = new PrepareImageResult(request);
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
LOGGER.info("Prepare image finished for {}", cloudContext);
} catch (RuntimeException e) {
PrepareImageResult failure = new PrepareImageResult(e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class ProvisionValidationHandler method accept.
@Override
public void accept(Event<ValidationRequest> event) {
LOGGER.info("Received event: {}", event);
ValidationRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
ValidationResult result;
try {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
CloudStack cloudStack = request.getCloudStack();
for (Validator v : connector.validators()) {
v.validate(ac, cloudStack);
}
result = new ValidationResult(request);
} catch (RuntimeException e) {
result = new ValidationResult(e, request);
}
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class GroupResourceService method update.
public List<CloudResourceStatus> update(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security, Collection<CloudResource> groupResources) throws Exception {
List<CloudResourceStatus> results = new ArrayList<>();
CloudContext cloudContext = auth.getCloudContext();
for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
List<CloudResource> resources = getResources(groupResources, builder.resourceType());
for (CloudResource resource : resources) {
CloudResourceStatus status = builder.update(context, auth, network, security, resource);
if (status != null) {
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(status.getCloudResource()), context, true);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
results.addAll(pollerResult);
}
}
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class GroupResourceService method deleteResources.
public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Collection<CloudResource> resources, Network network, boolean cancellable) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
List<GroupResourceBuilder> builderChain = resourceBuilders.group(cloudContext.getPlatform());
for (int i = builderChain.size() - 1; i >= 0; i--) {
GroupResourceBuilder builder = builderChain.get(i);
List<CloudResource> specificResources = getResources(resources, builder.resourceType());
for (CloudResource resource : specificResources) {
if (resource.getStatus() == CommonStatus.CREATED) {
CloudResource deletedResource = builder.delete(context, auth, resource, network);
if (deletedResource != null) {
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(deletedResource), context, cancellable);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
results.addAll(pollerResult);
}
}
resourceNotifier.notifyDeletion(resource, cloudContext);
}
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class NetworkResourceService method buildResources.
public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
if (pollGroup != null && CANCELLED.equals(pollGroup)) {
break;
}
try {
CloudResource buildableResource = builder.create(context, auth, network);
createResource(auth, buildableResource);
CloudResource resource = builder.build(context, auth, network, security, buildableResource);
updateResource(auth, resource);
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
results.addAll(pollerResult);
} catch (ResourceNotNeededException e) {
LOGGER.warn("Skipping resource creation: {}", e.getMessage());
}
}
return results;
}
Aggregations