Ec2IaasHandler extends AbstractThreadedTargetHandler { static String expandVolumeName(String nameTemplate, String appName, String instanceName) { if(! Utils.isEmptyOrWhitespaces(nameTemplate)) { String name = nameTemplate.replace(TPL_VOLUME_NAME, instanceName); name = name.replace(TPL_VOLUME_APP, appName); name = name.replaceAll("[\\W_-]", "-"); return name; } return nameTemplate; }  @Override String getTargetId(); @Override String createMachine( TargetHandlerParameters parameters ); @Override MachineConfigurator machineConfigurator( TargetHandlerParameters parameters, String machineId ); @Override boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ); @Override void terminateMachine( TargetHandlerParameters parameters, String machineId ); @Override String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ); static AmazonEC2 createEc2Client( Map<String,String> targetProperties ); static final String TARGET_ID; }
@Test public void testExpandVolumeName() { String name = "roboconf-" + TPL_VOLUME_APP + "-" + TPL_VOLUME_NAME; Assert.assertEquals("roboconf-app-inst", expandVolumeName(name, "app", "inst")); name = "cache-" + TPL_VOLUME_NAME; Assert.assertEquals("cache-inst4", expandVolumeName(name, "app2", "inst4")); name = "pre-" + TPL_VOLUME_APP + "-post"; Assert.assertEquals("pre-app2-post", expandVolumeName(name, "app2", "inst")); name = "pre-" + TPL_VOLUME_APP + "-post 2"; Assert.assertEquals("pre-app-51--post-2", expandVolumeName(name, "app 51 ", "vm 1")); }