@Test public void testGetStackParameters() { when(network.getStringParameter("subnetId")).thenReturn("subnet-1234"); when(databaseServer.getStorageSize()).thenReturn(Long.valueOf(50L)); when(databaseServer.getParameter("backupRetentionPeriod", Integer.class)).thenReturn(Integer.valueOf(1)); when(databaseServer.getFlavor()).thenReturn("db.m3.medium"); when(databaseServer.getServerId()).thenReturn("myserver"); when(databaseServer.getEngine()).thenReturn(DatabaseEngine.POSTGRESQL); when(databaseServer.getStringParameter("engineVersion")).thenReturn("10.6"); when(databaseServer.getStringParameter("multiAZ")).thenReturn("true"); when(databaseServer.getStringParameter("storageType")).thenReturn("gp2"); when(databaseServer.getPort()).thenReturn(Integer.valueOf(5432)); 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); assertContainsParameter(parameters, "AllocatedStorageParameter", "50"); assertContainsParameter(parameters, "BackupRetentionPeriodParameter", "1"); assertContainsParameter(parameters, "DBInstanceClassParameter", "db.m3.medium"); assertContainsParameter(parameters, "DBInstanceIdentifierParameter", "myserver"); assertContainsParameter(parameters, "DBSubnetGroupNameParameter", "dsg-myserver"); assertContainsParameter(parameters, "DBSubnetGroupSubnetIdsParameter", "subnet-1234"); assertContainsParameter(parameters, "EngineParameter", "postgres"); assertContainsParameter(parameters, "EngineVersionParameter", "10.6"); assertContainsParameter(parameters, "MasterUsernameParameter", "root"); assertContainsParameter(parameters, "MasterUserPasswordParameter", "cloudera"); assertContainsParameter(parameters, "MultiAZParameter", "true"); assertContainsParameter(parameters, "PortParameter", "5432"); assertContainsParameter(parameters, "StorageTypeParameter", "gp2"); assertContainsParameter(parameters, "VPCSecurityGroupsParameter", "sg-1234,sg-5678"); assertContainsParameter(parameters, "DeletionProtectionParameter", "false"); parameters = underTest.getStackParameters(authenticatedContext, databaseStack, true); 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);  }