@Test public void testMessage_changeInstanceState() throws Exception { MsgCmdChangeInstanceState msg = new MsgCmdChangeInstanceState( "/o/mp/k", InstanceStatus.DEPLOYED_STARTED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState((String) null, InstanceStatus.NOT_DEPLOYED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState( new Instance( "test" ), InstanceStatus.NOT_DEPLOYED ); checkBasics( msg, MsgCmdChangeInstanceState.class ); Map<String,byte[]> fileNameToFileContent = new HashMap<> (); fileNameToFileContent.put( "readme.txt", new byte[ 90 ]); msg = new MsgCmdChangeInstanceState( "/oops", InstanceStatus.NOT_DEPLOYED, fileNameToFileContent ); checkBasics( msg, MsgCmdChangeInstanceState.class ); msg = new MsgCmdChangeInstanceState((Instance) null, InstanceStatus.NOT_DEPLOYED, fileNameToFileContent ); checkBasics( msg, MsgCmdChangeInstanceState.class ); }
/** * Deploys an instance. * @param msg the message to process * @throws IOException if an error occurred with the messaging or while manipulating the file system * @throws PluginException if something went wrong with the plug-in */ void processMsgChangeInstanceState( MsgCmdChangeInstanceState msg ) throws IOException, PluginException { PluginInterface plugin; Instance instance = InstanceHelpers.findInstanceByPath( this.scopedInstance, msg.getInstancePath()); if( instance == null ) this.logger.severe( "No instance matched " + msg.getInstancePath() + " on the agent. Request to deploy it is dropped." ); else if( instance.getParent() == null ) this.logger.severe( "No action on the root instance is permitted." ); else if(( plugin = this.agent.findPlugin( instance )) == null ) this.logger.severe( "No plug-in was found to deploy " + msg.getInstancePath() + "." ); else AbstractLifeCycleManager .build( instance, this.agent.getApplicationName(), this.messagingClient) .changeInstanceState( instance, plugin, msg.getNewState(), msg.getFileNameToFileContent()); }
@Override public void changeInstanceState( ManagedApplication ma, Instance instance, InstanceStatus newStatus ) throws IOException, TargetException { this.messagingMngr.checkMessagingConfiguration(); String instancePath = InstanceHelpers.computeInstancePath( instance ); this.logger.fine( "Trying to change the state of " + instancePath + " to " + newStatus + " in " + ma.getName() + "..." ); if( InstanceHelpers.isTarget( instance )) { List<InstanceStatus> es = Arrays.asList( InstanceStatus.DEPLOYED_STARTED, InstanceStatus.DEPLOYING, InstanceStatus.STARTING, InstanceStatus.PROBLEM ); if( newStatus == InstanceStatus.NOT_DEPLOYED && es.contains( instance.getStatus())) undeployTarget( ma, instance ); else if( instance.getStatus() == InstanceStatus.NOT_DEPLOYED && newStatus == InstanceStatus.DEPLOYED_STARTED ) deployTarget( ma, instance ); else this.logger.warning( "Ignoring a request to update a scoped instance's state. New state was " + newStatus ); } else { Map<String,byte[]> instanceResources = null; if( newStatus == InstanceStatus.DEPLOYED_STARTED || newStatus == InstanceStatus.DEPLOYED_STOPPED ) instanceResources = ResourceUtils.storeInstanceResources( ma.getTemplateDirectory(), instance ); MsgCmdChangeInstanceState message = new MsgCmdChangeInstanceState( instance, newStatus, instanceResources ); this.messagingMngr.sendMessageSafely( ma, instance, message ); this.logger.fine( "A message was (or will be) sent to the agent to change the state of " + instancePath + " in " + ma.getName() + "." ); } }
MsgCmdChangeInstanceState localMsg = new MsgCmdChangeInstanceState( inst, InstanceStatus.NOT_DEPLOYED ); try { processMsgChangeInstanceState( localMsg );
dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdChangeInstanceState( rootInstance, InstanceStatus.DEPLOYED_STARTED )); Thread.sleep( getDelay()); Assert.assertEquals( 3, agentMessages.size()); dmClient.sendMessageToAgent( app, rootInstance, new MsgCmdChangeInstanceState( rootInstance, InstanceStatus.DEPLOYED_STARTED )); Thread.sleep( getDelay()); Assert.assertEquals( 3, agentMessages.size());
dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdSetScopedInstance( app1_root2, null, null, null )); dmClient.sendMessageToAgent( app2, app2_root, new MsgCmdRemoveInstance( app2_root )); dmClient.sendMessageToAgent( app2, app2_root, new MsgCmdChangeInstanceState( app2_root, InstanceStatus.DEPLOYED_STOPPED )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdRemoveInstance( app1_root2 )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdRemoveInstance( app1_root2 )); dmClient.sendMessageToAgent( app1, app1_root2, new MsgCmdChangeInstanceState( app1_root2, InstanceStatus.NOT_DEPLOYED )); dmClient.sendMessageToAgent( app1, app1_root1, new MsgCmdRemoveInstance( app1_root1 )); dmClient.sendMessageToAgent( app1, app1_root1, new MsgCmdSetScopedInstance( app1_root1 ));