use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView 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.azure.view.AzureCredentialView in project cloudbreak by hortonworks.
the class AzureResourceConnector method collectResourcesToRemove.
@Override
public Map<String, Map<String, Object>> collectResourcesToRemove(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms) {
AzureClient client = ac.getParameter(AzureClient.class);
AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
String stackName = azureUtils.getStackName(ac.getCloudContext());
Map<String, Map<String, Object>> resp = new HashMap<>(vms.size());
for (CloudInstance instance : vms) {
resp.put(instance.getInstanceId(), collectInstanceResourcesToRemove(ac, stack, client, azureCredentialView, stackName, instance));
}
return resp;
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildTestVirtualNetworkNamePrefix.
@Test
public void buildTestVirtualNetworkNamePrefix() {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, containsString("virtualNetworkNamePrefix"));
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildWithInstanceGroupTypeCoreShouldNotContainsGatewayCustomData.
@Test
public void buildWithInstanceGroupTypeCoreShouldNotContainsGatewayCustomData() throws Exception {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, not(containsString("\"customData\": \"" + base64EncodedUserData(GATEWAY_CUSTOM_DATA) + '"')));
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildNoPublicIpNoFirewallWithTags.
@Test
public void buildNoPublicIpNoFirewallWithTags() {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
when(azureUtils.isPrivateIp(any())).then(invocation -> true);
when(azureUtils.isNoSecurityGroups(any())).then(invocation -> true);
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Map<String, String> userDefinedTags = Maps.newHashMap();
userDefinedTags.put("testtagkey1", "testtagvalue1");
userDefinedTags.put("testtagkey2", "testtagvalue2");
cloudStack = new CloudStack(groups, network, image, parameters, userDefinedTags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, not(containsString("publicIPAddress")));
assertThat(templateString, not(containsString("networkSecurityGroups")));
assertThat(templateString, containsString("testtagkey"));
assertThat(templateString, containsString("testtagvalue"));
}
Aggregations