use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method collectResources.
private List<CloudResource> collectResources(AuthenticatedContext authenticatedContext, PersistenceNotifier notifier, Stack heatStack, CloudStack stack, NeutronNetworkView neutronNetworkView) {
List<CloudResource> cloudResources = newArrayList();
CloudResource heatResource = new Builder().type(ResourceType.HEAT_STACK).name(heatStack.getId()).build();
try {
notifier.notifyAllocation(heatResource, authenticatedContext.getCloudContext());
} catch (RuntimeException ignored) {
// Rollback
terminate(authenticatedContext, stack, Collections.singletonList(heatResource));
}
cloudResources.add(heatResource);
if (!neutronNetworkView.isProviderNetwork()) {
if (!neutronNetworkView.isExistingNetwork()) {
CloudResource r = CloudResource.builder().type(ResourceType.OPENSTACK_NETWORK).name(OpenStackConstants.NETWORK_ID).build();
cloudResources.add(r);
}
if (!neutronNetworkView.isExistingSubnet()) {
CloudResource r = CloudResource.builder().type(ResourceType.OPENSTACK_SUBNET).name(OpenStackConstants.SUBNET_ID).build();
cloudResources.add(r);
}
}
return cloudResources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class MockResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
for (CloudResource cloudResource : resources) {
CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(cloudResource, CREATED);
cloudResourceStatuses.add(cloudResourceStatus);
}
int createResourceCount = 0;
for (int i = 0; i < stack.getGroups().size(); i++) {
createResourceCount += stack.getGroups().get(i).getInstancesSize();
}
createResourceCount -= resources.size();
if (createResourceCount > 0) {
for (int i = 0; i < createResourceCount; i++) {
CloudResource cloudResource = new Builder().type(ResourceType.MOCK_INSTANCE).status(CommonStatus.CREATED).name("cloudinstance" + cloudResourceStatuses.size()).reference("").persistent(true).build();
cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, CREATED));
}
}
return cloudResourceStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class AzureResourceConnector method launch.
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
String stackName = azureUtils.getStackName(ac.getCloudContext());
String resourceGroupName = azureUtils.getResourceGroupName(ac.getCloudContext());
AzureClient client = ac.getParameter(AzureClient.class);
AzureStackView azureStackView = getAzureStack(azureCredentialView, ac.getCloudContext(), stack, getNumberOfAvailableIPsInSubnets(client, stack.getNetwork()));
String customImageId = azureStorage.getCustomImageId(client, ac, stack);
String template = azureTemplateBuilder.build(stackName, customImageId, azureCredentialView, azureStackView, ac.getCloudContext(), stack);
String parameters = azureTemplateBuilder.buildParameters(ac.getCloudCredential(), stack.getNetwork(), stack.getImage());
Boolean encrytionNeeded = azureStorage.isEncrytionNeeded(stack.getParameters());
try {
String region = ac.getCloudContext().getLocation().getRegion().value();
if (AzureUtils.hasUnmanagedDisk(stack)) {
Map<String, AzureDiskType> storageAccounts = azureStackView.getStorageAccounts();
for (Entry<String, AzureDiskType> entry : storageAccounts.entrySet()) {
azureStorage.createStorage(client, entry.getKey(), entry.getValue(), resourceGroupName, region, encrytionNeeded, stack.getTags());
}
}
if (!client.templateDeploymentExists(resourceGroupName, stackName)) {
Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, stackName, template, parameters);
LOGGER.info("created template deployment for launch: {}", templateDeployment.exportTemplate().template());
if (!azureUtils.isExistingNetwork(stack.getNetwork())) {
client.collectAndSaveNetworkAndSubnet(resourceGroupName, stackName, notifier, ac.getCloudContext());
}
}
} catch (CloudException e) {
LOGGER.error("Provisioning error, cloud exception happened: ", e);
if (e.body() != null && e.body().details() != null) {
String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", "));
throw new CloudConnectorException(String.format("Stack provisioning failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details));
} else {
throw new CloudConnectorException(String.format("Stack provisioning failed: '%s', please go to Azure Portal for detailed message", e));
}
} catch (Exception e) {
LOGGER.error("Provisioning error:", e);
throw new CloudConnectorException(String.format("Error in provisioning stack %s: %s", stackName, e.getMessage()));
}
CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(stackName).build();
List<CloudResourceStatus> resources = check(ac, Collections.singletonList(cloudResource));
LOGGER.debug("Launched resources: {}", resources);
return resources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class AzureSetup method prerequisites.
@Override
public void prerequisites(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier persistenceNotifier) {
String storageGroup = azureUtils.getResourceGroupName(ac.getCloudContext());
CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(storageGroup).build();
String region = ac.getCloudContext().getLocation().getRegion().value();
try {
AzureClient client = ac.getParameter(AzureClient.class);
persistenceNotifier.notifyAllocation(cloudResource, ac.getCloudContext());
if (!client.resourceGroupExists(storageGroup)) {
client.createResourceGroup(storageGroup, region, stack.getTags(), defaultCostTaggingService.prepareTemplateTagging());
}
} catch (Exception ex) {
throw new CloudConnectorException(ex);
}
LOGGER.debug("setup has been executed");
}
Aggregations