@Override public void start( Instance instance ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.info( this.agentId + " is starting instance " + name + "." ); this.currentState = InstanceStatus.DEPLOYED_STARTED; }
@Override public void undeploy( Instance instance ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.info( this.agentId + " is undeploying instance " + name + "." ); this.currentState = InstanceStatus.NOT_DEPLOYED; }
@Override public void deploy( Instance instance ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.info( this.agentId + " is deploying instance " + name + "." ); this.currentState = InstanceStatus.DEPLOYED_STOPPED; }
@Override public void update( Instance instance, Import importChanged, InstanceStatus statusChanged ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.info( this.agentId + " is updating instance " + name + "." ); }
@Override public void stop( Instance instance ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.info( this.agentId + " is stopping instance " + name + "." ); this.currentState = InstanceStatus.DEPLOYED_STOPPED; }
@Override public void initialize( Instance instance ) throws PluginException { String name = instance != null ? instance.getName() : null; this.logger.fine( this.agentId + " is initializing the plug-in for " + name + "." ); // This class is mainly used for test and dev' purpose. // So, we can store the information in the instance without any major impact. if( instance != null ) instance.data.put( INIT_PROPERTY, "true" ); }
/** * Details for an instance. * @param instance the instance * @return an object with error details */ public static ErrorDetails instance( Instance instance ) { return new ErrorDetails( instance.getName(), ErrorDetailsKind.INSTANCE ); }
@Override public void initialize( Instance instance ) throws PluginException { this.logger.fine( this.agentId + " is initializing the plug-in for " + instance.getName()); try { installPuppetModules( instance ); } catch( Exception e ) { throw new PluginException( e ); } }
/** * Determines whether an instance name is not already used by a sibling instance. * @param application the application (not null) * @param parentInstance the parent instance (can be null to indicate a root instance) * @param nameToSearch the name to search * @return true if a child instance of <code>parentInstance</code> has the same name, false otherwise */ public static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ) { boolean hasAlreadyAChildWithThisName = false; Collection<Instance> list = parentInstance == null ? application.getRootInstances() : parentInstance.getChildren(); for( Iterator<Instance> it = list.iterator(); it.hasNext() && ! hasAlreadyAChildWithThisName; ) { hasAlreadyAChildWithThisName = Objects.equals( nameToSearch, it.next().getName()); } return hasAlreadyAChildWithThisName; }
/** * Builds a map with the variables defined by this class. * @param instance a non-null instance * @return a non-null map where all the properties here are mapped to their values for this instance */ public static Map<String,String> buildReferenceMap( Instance instance ) { Map<String,String> result = new HashMap<> (); String instancePath = InstanceHelpers.computeInstancePath( instance ); result.put( ROBOCONF_INSTANCE_NAME, instance.getName()); result.put( ROBOCONF_INSTANCE_PATH, instancePath ); result.put( ROBOCONF_COMPONENT_NAME, instance.getComponent().getName()); result.put( ROBOCONF_CLEAN_INSTANCE_PATH, cleanInstancePath( instancePath )); result.put( ROBOCONF_CLEAN_REVERSED_INSTANCE_PATH, cleanReversedInstancePath( instancePath )); return result; }
@Override public void start( Instance instance ) throws PluginException { this.logger.fine( this.agentId + " is starting instance " + instance.getName()); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); try { callPuppetScript( instance, "start", PuppetState.RUNNING, null, false, instanceDirectory ); } catch( Exception e ) { throw new PluginException( e ); } }
@Override public void deploy( Instance instance ) throws PluginException { this.logger.fine( this.agentId + " is deploying instance " + instance.getName()); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); try { callPuppetScript( instance, "deploy", PuppetState.STOPPED, null, false, instanceDirectory ); } catch( Exception e ) { throw new PluginException( e ); } }
@Override public void stop( Instance instance ) throws PluginException { this.logger.fine( this.agentId + " is stopping instance " + instance.getName()); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); try { callPuppetScript( instance, "stop", PuppetState.STOPPED, null, false, instanceDirectory ); } catch( Exception e ) { throw new PluginException( e ); } }
@Override public void undeploy( Instance instance ) throws PluginException { this.logger.fine( this.agentId + " is undeploying instance " + instance.getName()); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); try { callPuppetScript( instance, "undeploy", PuppetState.UNDEF, null, false, instanceDirectory ); } catch( Exception e ) { throw new PluginException( e ); } }
@Override public void update(Instance instance, Import importChanged, InstanceStatus statusChanged) throws PluginException { this.logger.fine( this.agentId + " is updating instance " + instance.getName()); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); try { callPuppetScript( instance, "update", PuppetState.UNDEF, importChanged, (statusChanged == InstanceStatus.DEPLOYED_STARTED), instanceDirectory ); } catch( Exception e ) { throw new PluginException( e ); } }
/** * Constructor. * @param instance */ public MsgCmdAddInstance( Instance instance ) { this.parentInstancePath = instance.getParent() == null ? null : InstanceHelpers.computeInstancePath( instance.getParent()); this.instanceName = instance.getName(); this.componentName = instance.getComponent() != null ? instance.getComponent().getName() : null; this.channels = instance.channels; this.data = instance.data; this.overridenExports = instance.overriddenExports; }
/** * Constructor. * @param instance */ public MsgCmdAddInstance( Instance instance ) { this.parentInstancePath = instance.getParent() == null ? null : InstanceHelpers.computeInstancePath( instance.getParent()); this.instanceName = instance.getName(); this.componentName = instance.getComponent() != null ? instance.getComponent().getName() : null; this.channels = instance.channels; this.data = instance.data; this.overridenExports = instance.overriddenExports; }
@Test public void testGetAllInstances() { Application app = new Application( new ApplicationTemplate()); Instance[] rootInstances = new Instance[ 8 ]; for( int i=0; i<rootInstances.length; i++ ) { rootInstances[ i ] = new Instance( "i-" + i ); InstanceHelpers.insertChild( rootInstances[ i ], new Instance( "child-" + i )); } app.getRootInstances().addAll( Arrays.asList( rootInstances )); List<Instance> allInstances = InstanceHelpers.getAllInstances( app ); Assert.assertEquals( rootInstances.length * 2, allInstances.size()); for( Instance rootInstance : rootInstances ) Assert.assertTrue( rootInstance.getName(), allInstances.contains( rootInstance )); }
@Test public void testChain() { Instance inst = new Instance().name( "ins" ).status( InstanceStatus.DEPLOYING ).component( null ).parent( null ); Assert.assertEquals( 0, inst.channels.size()); Assert.assertEquals( "ins", inst.getName()); Assert.assertEquals( InstanceStatus.DEPLOYING, inst.getStatus()); Assert.assertNull( inst.getComponent()); Assert.assertNull( inst.getParent()); Assert.assertEquals( 1, inst.channel( "woo" ).channels.size()); Assert.assertEquals( 2, inst.channel( "yeah" ).channels.size()); Assert.assertEquals( 2, inst.channel( "woo" ).channels.size()); }
@Test public void testBuildRoutingKeyForAgent_Instance() { Instance inst = new Instance( "my-root" ); Assert.assertNotNull( MessagingUtils.buildTopicNameForAgent( inst )); Assert.assertEquals( MessagingUtils.buildTopicNameForAgent( inst ), MessagingUtils.buildTopicNameForAgent( inst.getName())); Instance childInstance = new Instance( "child" ); InstanceHelpers.insertChild( inst, childInstance ); Assert.assertEquals( MessagingUtils.buildTopicNameForAgent( childInstance ), MessagingUtils.buildTopicNameForAgent( inst )); }