@Test( expected = IOException.class ) public void testAssociationWithInvalidTargetId() throws Exception { TestApplication app = new TestApplication(); String mySqlPath = InstanceHelpers.computeInstancePath( app.getMySqlVm()); this.mngr.associateTargetWith( "invalid", app, mySqlPath ); }
@Override public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { boolean valid = false; if( instancePathOrComponentName == null ) { valid = true; } else if( instancePathOrComponentName.startsWith( "@" )) { Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 )); valid = comp != null; } else { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); valid = instance != null; if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } if( valid ) saveAssociation( app, targetId, instancePathOrComponentName, true ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { boolean valid = false; if( instancePathOrComponentName == null ) { valid = true; } else if( instancePathOrComponentName.startsWith( "@" )) { Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 )); valid = comp != null; } else { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); valid = instance != null; if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } if( valid ) saveAssociation( app, targetId, instancePathOrComponentName, true ); } }
TargetsMngrImpl implements ITargetsMngr { @Override public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { boolean valid = false; if( instancePathOrComponentName == null ) { valid = true; } else if( instancePathOrComponentName.startsWith( "@" )) { Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 )); valid = comp != null; } else { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); valid = instance != null; if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } if( valid ) saveAssociation( app, targetId, instancePathOrComponentName, true ); } TargetsMngrImpl( IConfigurationMngr configurationMngr ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { boolean valid = false; if( instancePathOrComponentName == null ) { valid = true; } else if( instancePathOrComponentName.startsWith( "@" )) { Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 )); valid = comp != null; } else { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); valid = instance != null; if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } if( valid ) saveAssociation( app, targetId, instancePathOrComponentName, true ); } TargetsMngrImpl( IConfigurationMngr configurationMngr ); @Override String createTarget( String targetContent ); @Override String createTarget( File targetPropertiesFile, ApplicationTemplate creator ); @Override void updateTarget( String targetId, String newTargetContent ); @Override void deleteTarget( String targetId ); @Override void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ); @Override void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ); @Override void copyOriginalMapping( Application app ); @Override void applicationWasDeleted( AbstractApplication app ); @Override TargetProperties findTargetProperties( AbstractApplication app, String instancePath ); @Override TargetProperties findTargetProperties( String targetId ); @Override String findTargetId( AbstractApplication app, String instancePath, boolean strict ); @Override String findTargetId( AbstractApplication app, String instancePath ); @Override Map<String,byte[]> findScriptResourcesForAgent( String targetId ); @Override Map<String,byte[]> findScriptResourcesForAgent( AbstractApplication app, Instance scopedInstance ); @Override File findScriptForDm( AbstractApplication app, Instance scopedInstance ); @Override List<TargetWrapperDescriptor> listAllTargets(); @Override TargetWrapperDescriptor findTargetById( String targetId ); @Override List<TargetWrapperDescriptor> listPossibleTargets( AbstractApplication app ); @Override void addHint( String targetId, AbstractApplication app ); @Override void removeHint( String targetId, AbstractApplication app ); @Override TargetProperties lockAndGetTarget( Application app, Instance scopedInstance ); @Override void unlockTarget( Application app, Instance scopedInstance ); @Override List<TargetUsageItem> findUsageStatistics( String targetId ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { boolean valid = false; if( instancePathOrComponentName == null ) { valid = true; } else if( instancePathOrComponentName.startsWith( "@" )) { Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 )); valid = comp != null; } else { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); valid = instance != null; if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } if( valid ) saveAssociation( app, targetId, instancePathOrComponentName, true ); } TargetsMngrImpl( IConfigurationMngr configurationMngr ); @Override String createTarget( String targetContent ); @Override String createTarget( File targetPropertiesFile, ApplicationTemplate creator ); @Override void updateTarget( String targetId, String newTargetContent ); @Override void deleteTarget( String targetId ); @Override void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ); @Override void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ); @Override void copyOriginalMapping( Application app ); @Override void applicationWasDeleted( AbstractApplication app ); @Override TargetProperties findTargetProperties( AbstractApplication app, String instancePath ); @Override TargetProperties findTargetProperties( String targetId ); @Override String findTargetId( AbstractApplication app, String instancePath, boolean strict ); @Override String findTargetId( AbstractApplication app, String instancePath ); @Override Map<String,byte[]> findScriptResourcesForAgent( String targetId ); @Override Map<String,byte[]> findScriptResourcesForAgent( AbstractApplication app, Instance scopedInstance ); @Override File findScriptForDm( AbstractApplication app, Instance scopedInstance ); @Override List<TargetWrapperDescriptor> listAllTargets(); @Override TargetWrapperDescriptor findTargetById( String targetId ); @Override List<TargetWrapperDescriptor> listPossibleTargets( AbstractApplication app ); @Override void addHint( String targetId, AbstractApplication app ); @Override void removeHint( String targetId, AbstractApplication app ); @Override TargetProperties lockAndGetTarget( Application app, Instance scopedInstance ); @Override void unlockTarget( Application app, Instance scopedInstance ); @Override List<TargetUsageItem> findUsageStatistics( String targetId );  }