/** * Acknowledges a heart beat. * @param scopedInstance a root instance */ public void acknowledgeHeartBeat( Instance scopedInstance ) { String count = scopedInstance.data.get( MISSED_HEARTBEATS ); if( count != null && Integer.parseInt( count ) > THRESHOLD ) this.logger.info( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " is alive and reachable again." ); // Store the moment the first ACK (without interruption) was received. // If we were deploying, store it. // If we were in problem, store it. // If we were already deployed and started, do NOT override it. if( scopedInstance.getStatus() != InstanceStatus.DEPLOYED_STARTED || ! scopedInstance.data.containsKey( Instance.RUNNING_FROM )) scopedInstance.data.put( Instance.RUNNING_FROM, String.valueOf( new Date().getTime())); scopedInstance.setStatus( InstanceStatus.DEPLOYED_STARTED ); scopedInstance.data.remove( MISSED_HEARTBEATS ); }
instance.setStatus( InstanceStatus.whichStatus( n.textValue()));
scopedInstance.setStatus( InstanceStatus.PROBLEM ); scopedInstance.data.put( Instance.LAST_PROBLEM, "Configuration failed. " + t.getMessage());
scopedInstance.setStatus( InstanceStatus.PROBLEM ); scopedInstance.data.put( Instance.LAST_PROBLEM, "Configuration failed. " + t.getMessage());
instance.setStatus( message.getNewStatus()); ImportHelpers.updateImports( instance, message.getNewImports());
int count = countAs == null ? 0 : Integer.parseInt( countAs ); if( ++ count > THRESHOLD ) { scopedInstance.setStatus( InstanceStatus.PROBLEM ); notificationMngr.instance( scopedInstance, this.application, EventType.CHANGED ); this.logger.severe( "Agent " + InstanceHelpers.computeInstancePath( scopedInstance ) + " has not sent heart beats for quite a long time. Status changed to PROBLEM." );
for( Instance i : InstanceHelpers.buildHierarchicalList( scopedInstance )) { InstanceStatus oldstatus = i.getStatus(); i.setStatus( InstanceStatus.NOT_DEPLOYED );
@Override public void changeInstanceState( Instance instance, PluginInterface plugin, InstanceStatus newStatus, Map<String,byte[]> fileNameToFileContent ) throws IOException, PluginException { // We can undeploy if( newStatus == InstanceStatus.NOT_DEPLOYED ) undeploy( instance, plugin ); // Stop is only a status change, no script or notification run else if( newStatus == InstanceStatus.DEPLOYED_STOPPED ) { instance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance )); List<Instance> childrenInstances = InstanceHelpers.buildHierarchicalList( instance ); childrenInstances.remove( instance ); for( Instance childInstance : childrenInstances ) { // Unresolved can only have "deployed stopped", "not deployed" and "waiting for ancestor" child status. if( childInstance.getStatus() == InstanceStatus.WAITING_FOR_ANCESTOR ) { childInstance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, childInstance )); } } } } }
|| instance.getParent().getStatus() == InstanceStatus.WAITING_FOR_ANCESTOR ) { instance.setStatus( InstanceStatus.WAITING_FOR_ANCESTOR ); this.logger.fine( instancePath + " will start as soon as its parent starts." ); + " cannot be started, dependencies are missing. Requesting exports from other agents." ); instance.setStatus( InstanceStatus.UNRESOLVED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance )); this.messagingClient.requestExportsFromOtherAgents( instance ); Utils.logException( this.logger, e ); instance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance ));
continue; i.setStatus( InstanceStatus.STOPPING ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, i )); this.messagingClient.listenToRequestsFromOtherAgents( ListenerCommand.STOP, i ); newStatus = InstanceStatus.WAITING_FOR_ANCESTOR; i.setStatus( newStatus ); forNotifications.add( i );
impactedInstance.setStatus( InstanceStatus.STARTING ); try { this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, impactedInstance )); plugin.start( impactedInstance ); impactedInstance.setStatus( InstanceStatus.DEPLOYED_STARTED ); this.logger.severe( "An error occured while starting " + InstanceHelpers.computeInstancePath( impactedInstance )); Utils.logException( this.logger, e ); impactedInstance.setStatus( oldState ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, impactedInstance ));
try { scopedInstance.setStatus( InstanceStatus.UNDEPLOYING ); this.notificationMngr.instance( scopedInstance, ma.getApplication(), EventType.CHANGED ); scopedInstance.setStatus( initialStatus ); scopedInstance.data.put( Instance.MACHINE_ID, machineId ); this.notificationMngr.instance( scopedInstance, ma.getApplication(), EventType.CHANGED );
instance.setStatus( InstanceStatus.DEPLOYING ); try { this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance )); instance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance )); Utils.logException( this.logger, e ); instance.setStatus( InstanceStatus.NOT_DEPLOYED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, instance ));
continue; i.setStatus( InstanceStatus.UNDEPLOYING ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, i )); this.messagingClient.unpublishExports( i ); i.setStatus( newStatus ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.appName, i ));
this.scopedInstance.setStatus( InstanceStatus.DEPLOYED_STARTED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.agent.getApplicationName(), this.scopedInstance ));
@Test public void testDuplicateInstance_singleInstance() { Instance original = new Instance( "inst" ).channel( "chan" ).component( new Component( "comp" )); original.overriddenExports.put( "test", "test" ); original.overriddenExports.put( "A.port", "8012" ); original.data.put( "some", "data" ); original.getImports().put( "facet-name", new ArrayList<Import> ()); original.setStatus( InstanceStatus.DEPLOYED_STARTED ); Instance copy = InstanceHelpers.replicateInstance( original ); Assert.assertEquals( original.getName(), copy.getName()); Assert.assertEquals( original.channels, copy.channels ); Assert.assertEquals( original.overriddenExports.size(), copy.overriddenExports.size()); Assert.assertEquals( "test", copy.overriddenExports.get( "test" )); Assert.assertEquals( "8012", copy.overriddenExports.get( "A.port" )); Assert.assertEquals( 0, copy.getImports().size()); Assert.assertEquals( original.getComponent(), copy.getComponent()); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, copy.getStatus()); }
@Test public void testHasAllRequiredImports_optional() throws Exception { Component clusterNodeComponent = new Component( "cluster" ).installerName( "whatever" ); clusterNodeComponent.addImportedVariable( new ImportedVariable( "cluster.ip", true, false )); clusterNodeComponent.addImportedVariable( new ImportedVariable( "cluster.port", true, false )); clusterNodeComponent.addExportedVariable( new ExportedVariable( "cluster.ip", null )); clusterNodeComponent.addExportedVariable( new ExportedVariable( "cluster.port", "9007" )); Instance i1 = new Instance( "inst 1" ).component( clusterNodeComponent ); i1.overriddenExports.put( "cluster.ip", "192.168.1.15" ); i1.setStatus( InstanceStatus.STARTING ); Instance i2 = new Instance( "inst 2" ).component( clusterNodeComponent ); i2.overriddenExports.put( "cluster.ip", "192.168.1.28" ); // The cluster node does not know about the other node Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i1, null )); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i2, null )); // The node is now aware of another node ImportHelpers.addImport( i1, "cluster", new Import( i2 )); i1.setStatus( InstanceStatus.STARTING ); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i1, null )); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i2, null )); i1.getImports().clear(); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i1, null )); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( i2, null )); }
@Test public void testHasAllRequiredImports_withWildcard() throws Exception { // Same test than "testHasAllRequiredImports_required" // but here, variable imports use a wild card. Component dbComponent = new Component( "database" ).installerName( "whatever" ); dbComponent.addExportedVariable( new ExportedVariable( "database.ip", null )); dbComponent.addExportedVariable( new ExportedVariable( "database.port", "3009" )); dbComponent.addExportedVariable( new ExportedVariable( "database.collection", "whatever" )); Component appServerComponent = new Component( "app-server" ).installerName( "whatever" ); appServerComponent.addExportedVariable( new ExportedVariable( "app-server.ip", null )); appServerComponent.addExportedVariable( new ExportedVariable( "app-server.port", "8009" )); appServerComponent.addImportedVariable( new ImportedVariable( "database.*", false, false )); Instance appServer = new Instance( "app server" ).component( appServerComponent ); appServer.overriddenExports.put( "app-server.ip", "192.168.1.15" ); appServer.setStatus( InstanceStatus.STARTING ); Instance database = new Instance( "database" ).component( dbComponent ); database.overriddenExports.put( "database.ip", "192.168.1.28" ); // The application server does not know about the database Assert.assertFalse( ImportHelpers.hasAllRequiredImports( appServer, Logger.getAnonymousLogger())); // The application server is now aware of the database ImportHelpers.addImport( appServer, "database", new Import( database )); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( appServer, null )); appServer.getImports().clear(); Assert.assertFalse( ImportHelpers.hasAllRequiredImports( appServer, null )); }
@Test public void testHasAllRequiredImports_required() throws Exception { Component dbComponent = new Component( "database" ).installerName( "whatever" ); dbComponent.addExportedVariable( new ExportedVariable( "database.ip", null )); dbComponent.addExportedVariable( new ExportedVariable( "database.port", "3009" )); dbComponent.addExportedVariable( new ExportedVariable( "database.collection", "whatever" )); Component appServerComponent = new Component( "app-server" ).installerName( "whatever" ); appServerComponent.addExportedVariable( new ExportedVariable( "app-server.ip", null )); appServerComponent.addExportedVariable( new ExportedVariable( "app-server.port", "8009" )); appServerComponent.addImportedVariable( new ImportedVariable( "database.ip", false, false )); appServerComponent.addImportedVariable( new ImportedVariable( "database.port", false, false )); appServerComponent.addImportedVariable( new ImportedVariable( "database.collection", true, false )); Instance appServer = new Instance( "app server" ).component( appServerComponent ); appServer.overriddenExports.put( "app-server.ip", "192.168.1.15" ); appServer.setStatus( InstanceStatus.STARTING ); Instance database = new Instance( "database" ).component( dbComponent ); database.overriddenExports.put( "database.ip", "192.168.1.28" ); // The application server does not know about the database Assert.assertFalse( ImportHelpers.hasAllRequiredImports( appServer, Logger.getAnonymousLogger())); // The application server is now aware of the database ImportHelpers.addImport( appServer, "database", new Import( database )); Assert.assertTrue( ImportHelpers.hasAllRequiredImports( appServer, null )); appServer.getImports().clear(); Assert.assertFalse( ImportHelpers.hasAllRequiredImports( appServer, null )); }