Search in sources :

Example 96 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildNoPublicIpNoFirewall.

@Test
public void buildNoPublicIpNoFirewall() {
    // 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()));
    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("publicIPAddress")));
    assertThat(templateString, not(containsString("networkSecurityGroups")));
}
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 97 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildWithInstanceGroupTypeGateway.

@Test
public void buildWithInstanceGroupTypeGateway() 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.GATEWAY, 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("\"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 98 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildTestExistingVNETName.

@Test
public void buildTestExistingVNETName() {
    // GIVEN
    when(azureUtils.isExistingNetwork(any())).thenReturn(true);
    when(azureUtils.getCustomNetworkId(any())).thenReturn("existingNetworkName");
    when(azureUtils.getCustomResourceGroupName(any())).thenReturn("existingResourceGroup");
    when(azureUtils.getCustomSubnetIds(any())).thenReturn(Arrays.asList("existingSubnet"));
    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("existingVNETName"));
    assertThat(templateString, containsString("existingSubnet"));
    assertThat(templateString, containsString("existingResourceGroup"));
}
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 99 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildTestDataDisksShouldThrowAssertionError.

@Test
@Ignore
public void buildTestDataDisksShouldThrowAssertionError() {
    // 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("[concat('datadisk', 'm0', '0')]"));
    assertThat(templateString, containsString("[concat('datadisk', 'm0', '1')]"));
    assertThat(templateString, containsString("[concat('datadisk', 'm0', '2')]"));
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 100 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class LogContextAspects method buildLogContextForPersistenceHandler.

@Before("com.sequenceiq.cloudbreak.logger.LogContextAspects.interceptResourcePersistenceHandlerAcceptMethod()")
public void buildLogContextForPersistenceHandler(JoinPoint joinPoint) {
    Event<ResourceNotification> event = (Event<ResourceNotification>) joinPoint.getArgs()[0];
    CloudContext cloudContext = event.getData().getCloudContext();
    buildMdcContext(cloudContext, event);
    LOGGER.debug("A Resource persistence handler's 'accept' method has been intercepted: {}, MDC logger context is built.", joinPoint.toShortString());
}
Also used : ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) Before(org.aspectj.lang.annotation.Before)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14