Search in sources :

Example 1 with AzureStackView

use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView 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);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Deployment(com.microsoft.azure.management.resources.Deployment) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) CloudError(com.microsoft.azure.CloudError) CloudException(com.microsoft.azure.CloudException) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudException(com.microsoft.azure.CloudException) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 2 with AzureStackView

use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView 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"));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 3 with AzureStackView

use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView 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) + '"')));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 4 with AzureStackView

use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView 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"));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 5 with AzureStackView

use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildTestResourceGroupName.

@Test
public void buildTestResourceGroupName() {
    // 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, not(containsString("resourceGroupName")));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Aggregations

AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)19 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)17 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Group (com.sequenceiq.cloudbreak.cloud.model.Group)17 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)17 Network (com.sequenceiq.cloudbreak.cloud.model.Network)17 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)17 HashMap (java.util.HashMap)17 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Test (org.junit.Test)17 CloudError (com.microsoft.azure.CloudError)2 CloudException (com.microsoft.azure.CloudException)2 Deployment (com.microsoft.azure.management.resources.Deployment)2 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)2 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)1