Ajout d'écouteurs de mise à l'échelle personnalisés

Vous pouvez créer un bundle de programme d'écoute de mise à l'échelle personnalisé en utilisant WebSphere Application Server Developer Tools for Eclipse. Un programme d'écoute de mise à l'échelle personnalisé est averti de toute action de mise à l'échelle en attente. Le programme d'écoute peut alors autoriser ou refuser l'action de mise à l'échelle. Il peut également décider de gérer l'action, fournissant ainsi une personnalisation complète du comportement de mise à l'échelle.

Avant de commencer

Assurez-vous que votre installation Liberty possède la fonction scalingController-1.0. Pour des informations sur les contrôleurs de mise à l'échelle, consultez Configuration de la fonction de mise à l'échelle automatique pour les collectivités Liberty et Contrôleur de mise à l'échelle.

Pourquoi et quand exécuter cette tâche

Vous devez implémenter l'interface de programme d'écoute et enregistrer la classe d'implémentation dans le registre de services. Votre programme d'écoute de mise à l'échelle peut autoriser ou refuser et gérer des actions de mise à l'échelle.

La documentation d'API Java pour chaque interface SPI Liberty est disponible dans un fichier comprimé distinct dans l'un des sous-répertoires de documentation d'API du répertoire ${wlp.install.dir}/dev.

Procédure

  1. Cliquez sur Fichier > Nouveau > Autre, puis développez OSGi.
  2. Clique sur OSGi Bundle Project et sur Next. La fenêtre New OSGi Bundle Project s'affiche.
  3. Entrez ScalingSPISampleBundle comme nom du projet. Dans la liste Target runtime, sélectionnez WebSphere Application Server Liberty. S'il n'existe aucun environnement d'exécution, cliquez sur New Runtime afin de créer une exécution WebSphere Application Server Liberty.
  4. Désélectionnez le bouton d'option Add bundle to application.
  5. Cliquez sur Next deux fois et accédez à la page OSGi Bundle.
  6. Dans la page OSGi Bundle, sélectionnez Generate an activator, a Java class that controls the life cycle of the bundle. Conservez la valeur scalingspisamplebundle.Activator  pour Activator name et cliquez sur Finish.
  7. Cliquez sur Fichier > Nouveau > Autre, puis développez OSGi.
  8. Cliquez sur Liberty Feature Project, puis sur Next. La fenêtre Liberty Feature Project s'affiche.
  9. Indiquez ScalingSPISampleFeature comme nom du projet.
  10. Dans la liste Target runtime, sélectionnez WebSphere Application Server Liberty et cliquez sur Next. La page OSGi Bundles Selection s'affiche.
  11. Dans la page OSGi Bundles Selection, sélectionnez ScalingSPISampleBundle 1.0.0 pour Contained Bundles et cliquez sur Finish.
  12. Cliquez sur Window > Preferences > Plug-in Development > Target Platform et sélectionnez WebSphere Application Server Liberty with SPI.
  13. Cliquez sur Apply et sur OK.
  14. Développez ScalingSPISampleBundle > BundleContent > META-INF et ouvrez le fichier MANIFEST.MF à l'aide de l'éditeur de manifeste de plug-in.
  15. Sélectionnez l'onglet Dependencies et ajoutez les packages com.ibm.wsspi.scaling.action.consumer et com.ibm.wsspi.scaling.action.controller au panneau Imported Packages. Vous devrez peut-être appuyer sur les touches Ctrl+S pour sauvegarder les modifications.
  16. Dans le projet ScalingSPISampleBundle, ajoutez une classe d'implémentation appelée ScalingSPISamplePlugin. Cette nouvelle classe implémente l'interface com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin.
    package scalingspisamplebundle;
    
    import com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin;
    import com.ibm.wsspi.scaling.action.controller.ScalingActionContext;
    import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionType;
    import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionDecision;;
    
    /**
     * This a sample Liberty scaling SPI plugin that acts as a template for developing a custom
     * SPI plugin. In this plugin, no actual work is done and the return value to the Liberty Scaling
     * controller is always DEFAULT_ACTION.
     * 
     */
    public class ScalingSPISamplePlugin implements ScalingActionPlugin {
    
        /** {@inheritDoc} */
        @Override
        public ActionDecision actionRequired(ScalingActionContext action) {
    
            ActionDecision returnType = ActionDecision.DEFAULT_ACTION;
    
            if (action.getActionType() == ActionType.START_SERVER) {
                returnType = startServer(action);
            }
            else if (action.getActionType() == ActionType.CREATE_SERVER) {
                returnType = createServer(action);
            }
            else if (action.getActionType() == ActionType.STOP_SERVER) {
                returnType = stopServer(action);
            }
    
            return returnType;
    
        }
    
        private ActionDecision startServer(ScalingActionContext action) {
            // perform some action to start a server
    
            return ActionDecision.DEFAULT_ACTION;
        }
    
        private ActionDecision createServer(ScalingActionContext action) {
            // perform some action to create a server
    
            return ActionDecision.DEFAULT_ACTION;
        }
    
        private ActionDecision stopServer(ScalingActionContext action) {
            // perform some action to stop a server
    
            return ActionDecision.DEFAULT_ACTION;
        }
    }
  17. Dans le projet ScalingSPISampleBundle, ouvrez la classe Activator et éditez la méthode start(BundleContext) pour ajouter le code enregistrant le nouveau service de programme d'écoute.
    public void start(BundleContext context) throws Exception {
        final Hashtable<String, Object> properties = new Hashtable<String, Object>();
        ScalingSPISamplePlugin scalingSPISamplePlugin = new ScalingSPISamplePlugin();
        context.registerService(ScalingActionPlugin.class, scalingSPISamplePlugin, properties);
    }

    Si vous êtes invité à importer une mappe de hachage (HashMap), choisissez d'importer java.util.HashMap.

  18. Cliquez avec le bouton droit sur le projet ScalingSPISampleFeature, puis cliquez sur Install Feature afin d'installer la fonction dans l'exécution Liberty.

    L'option de menu Install Feature se trouve dans la vue Enterprise Explorer de la perspective Java EE.

  19. Editez le fichier server.xml pour activer ScalingSPISampleFeature.
    ...
    <featureManager>
      ...
      <feature>scalingController-1.0</feature>
      <feature>usr:ScalingSPISampleFeature</feature>
    </featureManager>
    ...

Icône indiquant le type de rubrique Rubrique Tâche

Nom du fichier : twlp_wve_add_scaling_listener.html