@Test public void testGetMinimalStackParameters() { when(network.getStringParameter("subnetId")).thenReturn("subnet-1234"); when(databaseServer.getStorageSize()).thenReturn(null); when(databaseServer.getParameter("backupRetentionPeriod", Integer.class)).thenReturn(null); when(databaseServer.getFlavor()).thenReturn("db.m3.medium"); when(databaseServer.getServerId()).thenReturn("myserver"); when(databaseServer.getEngine()).thenReturn(DatabaseEngine.POSTGRESQL); when(databaseServer.getStringParameter("engineVersion")).thenReturn(null); when(databaseServer.getStringParameter("multiAZ")).thenReturn(null); when(databaseServer.getStringParameter("storageType")).thenReturn(null); when(databaseServer.getPort()).thenReturn(null); when(databaseServer.getRootUserName()).thenReturn("root"); when(databaseServer.getRootPassword()).thenReturn("cloudera"); when(databaseServer.getSecurity().getCloudSecurityIds()).thenReturn(List.of("sg-1234", "sg-5678")); when(cloudContext.getUserName()).thenReturn("bob@cloudera.com"); Collection<Parameter> parameters = underTest.getStackParameters(authenticatedContext, databaseStack, false); assertDoesNotContainParameter(parameters, "AllocatedStorageParameter"); assertDoesNotContainParameter(parameters, "BackupRetentionPeriodParameter"); assertDoesNotContainParameter(parameters, "EngineVersionParameter"); assertDoesNotContainParameter(parameters, "MultiAZParameter"); assertDoesNotContainParameter(parameters, "StorageTypeParameter"); assertDoesNotContainParameter(parameters, "PortParameter"); assertContainsParameter(parameters, "DeletionProtectionParameter", "false"); parameters = underTest.getStackParameters(authenticatedContext, databaseStack, true); assertDoesNotContainParameter(parameters, "AllocatedStorageParameter"); assertDoesNotContainParameter(parameters, "BackupRetentionPeriodParameter"); assertDoesNotContainParameter(parameters, "EngineVersionParameter"); assertDoesNotContainParameter(parameters, "MultiAZParameter"); assertDoesNotContainParameter(parameters, "StorageTypeParameter"); assertDoesNotContainParameter(parameters, "PortParameter"); assertContainsParameter(parameters, "DeletionProtectionParameter", "true"); }
private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); String keyPairName = awsClient.getKeyPairName(ac); if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication()); } Collection<Parameter> parameters = new ArrayList<>(); if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) { addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT); } addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT); parameters.addAll(asList( new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack)) )); if (awsInstanceProfileView.isInstanceProfileAvailable()) { parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile())); } if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) { parameters.add(new Parameter().withParameterKey("AvailabilitySet") .withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value())); } if (awsNetworkView.isExistingVPC()) { parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc())); if (awsNetworkView.isExistingIGW()) { parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw())); } if (awsNetworkView.isExistingSubnet()) { parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet())); } else { parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr)); } } return parameters; }
AwsStackRequestHelper { private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); String keyPairName = awsClient.getKeyPairName(ac); if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication()); } Collection<Parameter> parameters = new ArrayList<>(); if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) { addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT); } addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT); parameters.addAll(asList( new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack)) )); if (awsInstanceProfileView.isInstanceProfileAvailable()) { parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile())); } if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) { parameters.add(new Parameter().withParameterKey("AvailabilitySet") .withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value())); } if (awsNetworkView.isExistingVPC()) { parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc())); if (awsNetworkView.isExistingIGW()) { parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw())); } if (awsNetworkView.isExistingSubnet()) { parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet())); } else { parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr)); } } return parameters; } }
AwsStackRequestHelper { private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); String keyPairName = awsClient.getKeyPairName(ac); if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication()); } Collection<Parameter> parameters = new ArrayList<>(); if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) { addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT); } addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT); parameters.addAll(asList( new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack)) )); if (awsInstanceProfileView.isInstanceProfileAvailable()) { parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile())); } if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) { parameters.add(new Parameter().withParameterKey("AvailabilitySet") .withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value())); } if (awsNetworkView.isExistingVPC()) { parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc())); if (awsNetworkView.isExistingIGW()) { parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw())); } if (awsNetworkView.isExistingSubnet()) { parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet())); } else { parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr)); } } return parameters; }  }
AwsStackRequestHelper { private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); String keyPairName = awsClient.getKeyPairName(ac); if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication()); } Collection<Parameter> parameters = new ArrayList<>(); if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) { addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT); } addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT); parameters.addAll(asList( new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack)) )); if (awsInstanceProfileView.isInstanceProfileAvailable()) { parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile())); } if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) { parameters.add(new Parameter().withParameterKey("AvailabilitySet") .withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value())); } if (awsNetworkView.isExistingVPC()) { parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc())); if (awsNetworkView.isExistingIGW()) { parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw())); } if (awsNetworkView.isExistingSubnet()) { parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet())); } else { parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr)); } } return parameters; }  CreateStackRequest createCreateStackRequest(AuthenticatedContext ac, CloudStack stack, String cFStackName, String subnet, String cfTemplate); CreateStackRequest createCreateStackRequest(AuthenticatedContext ac, DatabaseStack stack, String cFStackName, String cfTemplate); UpdateStackRequest createUpdateStackRequest(AuthenticatedContext ac, CloudStack stack, String cFStackName, String cfTemplate); DeleteStackRequest createDeleteStackRequest(String cFStackName); }
AwsStackRequestHelper { private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); String keyPairName = awsClient.getKeyPairName(ac); if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) { keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication()); } Collection<Parameter> parameters = new ArrayList<>(); if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) { addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT); } addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT); parameters.addAll(asList( new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack)) )); if (awsInstanceProfileView.isInstanceProfileAvailable()) { parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile())); } if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) { parameters.add(new Parameter().withParameterKey("AvailabilitySet") .withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value())); } if (awsNetworkView.isExistingVPC()) { parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc())); if (awsNetworkView.isExistingIGW()) { parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw())); } if (awsNetworkView.isExistingSubnet()) { parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet())); } else { parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr)); } } return parameters; }  CreateStackRequest createCreateStackRequest(AuthenticatedContext ac, CloudStack stack, String cFStackName, String subnet, String cfTemplate); CreateStackRequest createCreateStackRequest(AuthenticatedContext ac, DatabaseStack stack, String cFStackName, String cfTemplate); UpdateStackRequest createUpdateStackRequest(AuthenticatedContext ac, CloudStack stack, String cFStackName, String cfTemplate); DeleteStackRequest createDeleteStackRequest(String cFStackName);  }