use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AwsResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
resumeAutoScaling(ac, stack);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
List<Group> scaledGroups = getScaledGroups(stack);
for (Group group : scaledGroups) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, cloudFormationClient, group.getName());
amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(asGroupName).withMaxSize(group.getInstancesSize()).withDesiredCapacity(group.getInstancesSize()));
LOGGER.info("Updated Auto Scaling group's desiredCapacity: [stack: '{}', to: '{}']", ac.getCloudContext().getId(), resources.size());
}
scheduleStatusChecks(stack, ac, cloudFormationClient);
suspendAutoScaling(ac, stack);
boolean mapPublicIpOnLaunch = isMapPublicOnLaunch(new AwsNetworkView(stack.getNetwork()), amazonEC2Client);
List<Group> gateways = getGatewayGroups(scaledGroups);
if (mapPublicIpOnLaunch && !gateways.isEmpty()) {
String cFStackName = getCloudFormationStackResource(resources).getName();
Map<String, String> eipAllocationIds = getElasticIpAllocationIds(cFStackName, cloudFormationClient);
for (Group gateway : gateways) {
List<String> eips = getEipsForGatewayGroup(eipAllocationIds, gateway);
List<String> freeEips = getFreeIps(eips, amazonEC2Client);
List<String> instanceIds = getInstancesForGroup(ac, amazonASClient, cloudFormationClient, gateway);
List<String> newInstances = instanceIds.stream().filter(iid -> gateway.getInstances().stream().noneMatch(inst -> iid.equals(inst.getInstanceId()))).collect(Collectors.toList());
associateElasticIpsToInstances(amazonEC2Client, freeEips, newInstances);
}
}
return singletonList(new CloudResourceStatus(getCloudFormationStackResource(resources), ResourceStatus.UPDATED));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AzureResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
AzureCredentialView azureCredentialView = new AzureCredentialView(authenticatedContext.getCloudCredential());
String stackName = azureUtils.getStackName(authenticatedContext.getCloudContext());
AzureStackView azureStackView = getAzureStack(azureCredentialView, authenticatedContext.getCloudContext(), stack, getNumberOfAvailableIPsInSubnets(client, stack.getNetwork()));
String customImageId = azureStorage.getCustomImageId(client, authenticatedContext, stack);
String template = azureTemplateBuilder.build(stackName, customImageId, azureCredentialView, azureStackView, authenticatedContext.getCloudContext(), stack);
String parameters = azureTemplateBuilder.buildParameters(authenticatedContext.getCloudCredential(), stack.getNetwork(), stack.getImage());
String resourceGroupName = azureUtils.getResourceGroupName(authenticatedContext.getCloudContext());
try {
String region = authenticatedContext.getCloudContext().getLocation().getRegion().value();
Map<String, AzureDiskType> storageAccounts = azureStackView.getStorageAccounts();
for (Entry<String, AzureDiskType> entry : storageAccounts.entrySet()) {
azureStorage.createStorage(client, entry.getKey(), entry.getValue(), resourceGroupName, region, azureStorage.isEncrytionNeeded(stack.getParameters()), stack.getTags());
}
Deployment templateDeployment = client.createTemplateDeployment(stackName, stackName, template, parameters);
LOGGER.info("created template deployment for upscale: {}", templateDeployment.exportTemplate().template());
CloudResource armTemplate = resources.stream().filter(r -> r.getType() == ResourceType.ARM_TEMPLATE).findFirst().orElseThrow(() -> new CloudConnectorException(String.format("Arm Template not found for: %s ", stackName)));
return Collections.singletonList(new CloudResourceStatus(armTemplate, ResourceStatus.IN_PROGRESS));
} catch (CloudException e) {
LOGGER.error("Upscale 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 upscale failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details));
} else {
throw new CloudConnectorException(String.format("Stack upscale failed: '%s', please go to Azure Portal for detailed message", e));
}
} catch (Exception e) {
throw new CloudConnectorException(String.format("Could not upscale: %s ", stackName), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AzureResourceConnector method check.
@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
String stackName = azureUtils.getStackName(authenticatedContext.getCloudContext());
for (CloudResource resource : resources) {
switch(resource.getType()) {
case ARM_TEMPLATE:
LOGGER.info("Checking Azure group stack status of: {}", stackName);
try {
CloudResourceStatus templateResourceStatus;
if (client.templateDeploymentExists(stackName, stackName)) {
Deployment resourceGroupDeployment = client.getTemplateDeployment(stackName, stackName);
templateResourceStatus = azureUtils.getTemplateStatus(resource, resourceGroupDeployment, client, stackName);
} else {
templateResourceStatus = new CloudResourceStatus(resource, ResourceStatus.DELETED);
}
result.add(templateResourceStatus);
} catch (CloudException e) {
if (e.response().code() == AzureConstants.NOT_FOUND) {
result.add(new CloudResourceStatus(resource, ResourceStatus.DELETED));
} else {
throw new CloudConnectorException(e.body().message(), e);
}
} catch (RuntimeException e) {
throw new CloudConnectorException(String.format("Invalid resource exception: %s", e.getMessage()), e);
}
break;
case AZURE_NETWORK:
case AZURE_SUBNET:
break;
default:
throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
}
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AzureUtils method getTemplateStatus.
public CloudResourceStatus getTemplateStatus(CloudResource resource, Deployment templateDeployment, AzureClient access, String stackName) {
String status = templateDeployment.provisioningState();
LOGGER.info("Azure stack status of: {} is: {}", resource.getName(), status);
ResourceStatus resourceStatus = AzureStackStatus.mapResourceStatus(status);
CloudResourceStatus armResourceStatus = null;
if (ResourceStatus.FAILED.equals(resourceStatus)) {
LOGGER.debug("Cloud resource status: {}", resourceStatus);
try {
// TODO: discuss with Doktorics why this is needed
DeploymentOperations templateDeploymentOperations = access.getTemplateDeploymentOperations(stackName, stackName);
for (DeploymentOperation deploymentOperation : templateDeploymentOperations.list()) {
if ("Failed".equals(deploymentOperation.provisioningState())) {
String statusMessage = (String) deploymentOperation.statusMessage();
armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status), statusMessage);
break;
}
}
} catch (RuntimeException e) {
armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status), e.getMessage());
}
} else {
LOGGER.debug("Cloud resource status: {}", resourceStatus);
armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status));
}
return armResourceStatus;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method checkResourceStatus.
private CloudResourceStatus checkResourceStatus(AuthenticatedContext authenticatedContext, String stackName, Collection<CloudResource> list, CloudResource resource, ResourceType openstackNetwork) {
CloudResourceStatus result;
result = getCloudResourceStatus(list, openstackNetwork, resource);
if (result.getStatus().isPermanent()) {
persistenceNotifier.notifyAllocation(result.getCloudResource(), authenticatedContext.getCloudContext());
}
return result;
}
Aggregations