@Test( expected = TargetException.class ) public void testValidateAll_duplicateVolumeName_emptyNameShouldResultInDefault() throws Exception { Map<String,String> targetProperties = new HashMap<>(); targetProperties.put( FLAVOR_NAME, UUID.randomUUID().toString()); targetProperties.put( TENANT_NAME, UUID.randomUUID().toString()); targetProperties.put( IMAGE_NAME, UUID.randomUUID().toString()); targetProperties.put( SECURITY_GROUP, UUID.randomUUID().toString()); targetProperties.put( USER, UUID.randomUUID().toString()); targetProperties.put( PASSWORD, UUID.randomUUID().toString()); targetProperties.put( KEY_PAIR, UUID.randomUUID().toString()); targetProperties.put( API_URL, UUID.randomUUID().toString()); targetProperties.put( USE_BLOCK_STORAGE, "a, b, ,," ); targetProperties.put( VOLUME_NAME_PREFIX + "a", "" ); targetProperties.put( VOLUME_MOUNT_POINT_PREFIX + "a", "/dev/sdc" ); targetProperties.put( VOLUME_MOUNT_POINT_PREFIX + "b", "/dev/sdd" ); validateAll( targetProperties, "app", "inst" ); }
static void validateAll( Map<String,String> targetProperties, String appName, String instanceName ) throws TargetException { validate( targetProperties ); Set<String> mountPoints = new HashSet<> (); Set<String> volumeNames = new HashSet<> (); for( String s : findStorageIds( targetProperties )) { String mountPoint = findStorageProperty( targetProperties, s, VOLUME_MOUNT_POINT_PREFIX ); if( mountPoints.contains( mountPoint )) throw new TargetException( "Mount point '" + mountPoint + "' is already used by another volume for this VM." ); mountPoints.add( mountPoint ); String volumeName = findStorageProperty( targetProperties, s, VOLUME_NAME_PREFIX ); volumeName = expandVolumeName( volumeName, appName, instanceName ); if( volumeNames.contains( volumeName )) throw new TargetException( "Volume name '" + volumeName + "' is already used by another volume for this VM." ); volumeNames.add( volumeName ); String volumesize = findStorageProperty( targetProperties, s, VOLUME_SIZE_GB_PREFIX ); try { Integer.valueOf( volumesize ); } catch( NumberFormatException e ) { throw new TargetException( "The volume size must be a valid integer.", e ); } } }
OpenstackIaasHandler extends AbstractThreadedTargetHandler { static void validateAll( Map<String,String> targetProperties, String appName, String instanceName ) throws TargetException { validate( targetProperties ); Set<String> mountPoints = new HashSet<> (); Set<String> volumeNames = new HashSet<> (); for( String s : findStorageIds( targetProperties )) { String mountPoint = findStorageProperty( targetProperties, s, VOLUME_MOUNT_POINT_PREFIX ); if( mountPoints.contains( mountPoint )) throw new TargetException( "Mount point '" + mountPoint + "' is already used by another volume for this VM." ); mountPoints.add( mountPoint ); String volumeName = findStorageProperty( targetProperties, s, VOLUME_NAME_PREFIX ); volumeName = expandVolumeName( volumeName, appName, instanceName ); if( volumeNames.contains( volumeName )) throw new TargetException( "Volume name '" + volumeName + "' is already used by another volume for this VM." ); volumeNames.add( volumeName ); String volumesize = findStorageProperty( targetProperties, s, VOLUME_SIZE_GB_PREFIX ); try { Integer.valueOf( volumesize ); } catch( NumberFormatException e ) { throw new TargetException( "The volume size must be a valid integer.", e ); } } } }
OpenstackIaasHandler extends AbstractThreadedTargetHandler { static void validateAll( Map<String,String> targetProperties, String appName, String instanceName ) throws TargetException { validate( targetProperties ); Set<String> mountPoints = new HashSet<> (); Set<String> volumeNames = new HashSet<> (); for( String s : findStorageIds( targetProperties )) { String mountPoint = findStorageProperty( targetProperties, s, VOLUME_MOUNT_POINT_PREFIX ); if( mountPoints.contains( mountPoint )) throw new TargetException( "Mount point '" + mountPoint + "' is already used by another volume for this VM." ); mountPoints.add( mountPoint ); String volumeName = findStorageProperty( targetProperties, s, VOLUME_NAME_PREFIX ); volumeName = expandVolumeName( volumeName, appName, instanceName ); if( volumeNames.contains( volumeName )) throw new TargetException( "Volume name '" + volumeName + "' is already used by another volume for this VM." ); volumeNames.add( volumeName ); String volumesize = findStorageProperty( targetProperties, s, VOLUME_SIZE_GB_PREFIX ); try { Integer.valueOf( volumesize ); } catch( NumberFormatException e ) { throw new TargetException( "The volume size must be a valid integer.", e ); } } }  }
OpenstackIaasHandler extends AbstractThreadedTargetHandler { static void validateAll( Map<String,String> targetProperties, String appName, String instanceName ) throws TargetException { validate( targetProperties ); Set<String> mountPoints = new HashSet<> (); Set<String> volumeNames = new HashSet<> (); for( String s : findStorageIds( targetProperties )) { String mountPoint = findStorageProperty( targetProperties, s, VOLUME_MOUNT_POINT_PREFIX ); if( mountPoints.contains( mountPoint )) throw new TargetException( "Mount point '" + mountPoint + "' is already used by another volume for this VM." ); mountPoints.add( mountPoint ); String volumeName = findStorageProperty( targetProperties, s, VOLUME_NAME_PREFIX ); volumeName = expandVolumeName( volumeName, appName, instanceName ); if( volumeNames.contains( volumeName )) throw new TargetException( "Volume name '" + volumeName + "' is already used by another volume for this VM." ); volumeNames.add( volumeName ); String volumesize = findStorageProperty( targetProperties, s, VOLUME_SIZE_GB_PREFIX ); try { Integer.valueOf( volumesize ); } catch( NumberFormatException e ) { throw new TargetException( "The volume size must be a valid integer.", e ); } } }  @Override String getTargetId(); @Override String createMachine( TargetHandlerParameters parameters ); @Override boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ); @Override MachineConfigurator machineConfigurator( TargetHandlerParameters parameters, String machineId ); @Override void terminateMachine( TargetHandlerParameters parameters, String machineId ); @Override String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ); }
OpenstackIaasHandler extends AbstractThreadedTargetHandler { static void validateAll( Map<String,String> targetProperties, String appName, String instanceName ) throws TargetException { validate( targetProperties ); Set<String> mountPoints = new HashSet<> (); Set<String> volumeNames = new HashSet<> (); for( String s : findStorageIds( targetProperties )) { String mountPoint = findStorageProperty( targetProperties, s, VOLUME_MOUNT_POINT_PREFIX ); if( mountPoints.contains( mountPoint )) throw new TargetException( "Mount point '" + mountPoint + "' is already used by another volume for this VM." ); mountPoints.add( mountPoint ); String volumeName = findStorageProperty( targetProperties, s, VOLUME_NAME_PREFIX ); volumeName = expandVolumeName( volumeName, appName, instanceName ); if( volumeNames.contains( volumeName )) throw new TargetException( "Volume name '" + volumeName + "' is already used by another volume for this VM." ); volumeNames.add( volumeName ); String volumesize = findStorageProperty( targetProperties, s, VOLUME_SIZE_GB_PREFIX ); try { Integer.valueOf( volumesize ); } catch( NumberFormatException e ) { throw new TargetException( "The volume size must be a valid integer.", e ); } } }  @Override String getTargetId(); @Override String createMachine( TargetHandlerParameters parameters ); @Override boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ); @Override MachineConfigurator machineConfigurator( TargetHandlerParameters parameters, String machineId ); @Override void terminateMachine( TargetHandlerParameters parameters, String machineId ); @Override String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ); static final String TARGET_ID; }