PorteDelegateVerificaConnettore.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.web.ctrlstat.servlet.pd;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.config.PortaDelegata;
  32. import org.openspcoop2.pdd.core.jmx.JMXUtils;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  37. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  38. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCore;
  39. import org.openspcoop2.web.lib.mvc.Costanti;
  40. import org.openspcoop2.web.lib.mvc.DataElement;
  41. import org.openspcoop2.web.lib.mvc.DataElementType;
  42. import org.openspcoop2.web.lib.mvc.ForwardParams;
  43. import org.openspcoop2.web.lib.mvc.GeneralData;
  44. import org.openspcoop2.web.lib.mvc.PageData;
  45. import org.openspcoop2.web.lib.mvc.Parameter;
  46. import org.openspcoop2.web.lib.mvc.ServletUtils;
  47. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  48. /***
  49.  *
  50.  * PorteApplicativeVerificaConnettore
  51.  *
  52.  * @author Giuliano Pintori (pintori@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class PorteDelegateVerificaConnettore extends Action {

  57.     @Override
  58.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  59.         HttpSession session = request.getSession(true);

  60.         // Inizializzo PageData
  61.         PageData pd = new PageData();

  62.         GeneralHelper generalHelper = new GeneralHelper(session);

  63.         // Inizializzo GeneralData
  64.         GeneralData gd = generalHelper.initGeneralData(request);

  65.         try {

  66.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  67.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  68.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  69.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  70.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  71.             int idInt = Integer.parseInt(id);
  72.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  73.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  74.             if(idAsps == null)
  75.                 idAsps = "";
  76.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  77.             if(idFruizione == null)
  78.                 idFruizione = "";
  79.            
  80.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  81.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  82.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  83.             }

  84.             // Preparo il menu
  85.             porteDelegateHelper.makeMenu();

  86.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  87.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);
  88.             ConnettoriCore connettoriCore = new ConnettoriCore(porteDelegateCore);

  89.             String tmpIdConnettore = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ID);
  90.             long idConnettore = Long.parseLong(tmpIdConnettore);
  91.            
  92.             String tmpAccessoDaGruppi = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI);
  93.             boolean accessoDaGruppi = "true".equalsIgnoreCase(tmpAccessoDaGruppi);
  94.            
  95.             String tmpConnettoreRegistro = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO);
  96.             boolean connettoreRegistro = "true".equalsIgnoreCase(tmpConnettoreRegistro);

  97.             String alias = porteDelegateHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_SISTEMA_NODO_CLUSTER);
  98.                        
  99.             // Prendo la lista di aliases
  100.             List<String> aliases = confCore.getJmxPdDAliases();
  101.             if(aliases==null || aliases.isEmpty()){
  102.                 throw new Exception("Pagina non prevista, la sezione configurazione non permette di accedere a questa pagina, se la configurazione non e' corretta");
  103.             }
  104.            
  105.            
  106.             org.openspcoop2.core.config.Connettore connettore = null;
  107.             if(connettoreRegistro) {
  108.                 connettore = connettoriCore.getConnettoreRegistro(idConnettore).mappingIntoConnettoreConfigurazione();
  109.             }
  110.             else {
  111.                 connettore = connettoriCore.getConnettoreConfig(idConnettore);
  112.             }
  113.             String labelConnettore = porteDelegateHelper.getLabelConnettore(connettore,false,false);
  114.            
  115.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  116.             String idporta = portaDelegata.getNome();

  117.            
  118.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  119.            
  120.             String labelPerPorta = null;
  121.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  122.                 if(!accessoDaGruppi) {
  123.                     lstParam.remove(lstParam.size()-1);
  124.                 }
  125.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  126.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VERIFICA_CONNETTORE_CONFIGURAZIONE_CONFIG_DI,
  127.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VERIFICA_CONNETTORE_CONFIGURAZIONE,
  128.                         portaDelegata);
  129.             }
  130.             else {
  131.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VERIFICA_CONNETTORE_CONFIGURAZIONE_CONFIG_DI+idporta;
  132.             }
  133.            
  134.             if(!accessoDaGruppi &&
  135.                 labelPerPorta.contains(CostantiControlStation.LABEL_DEL_GRUPPO)) {
  136.                 labelPerPorta = labelPerPorta.substring(0, labelPerPorta.indexOf(CostantiControlStation.LABEL_DEL_GRUPPO));
  137.             }
  138.            
  139.             lstParam.add(new Parameter(labelPerPorta,  null));

  140.            
  141.            
  142.             ServletUtils.setPageDataTitle(pd, lstParam);
  143.            
  144.             // imposto menu' contestuale
  145.             porteDelegateHelper.impostaComandiMenuContestualePD(idSoggFruitore, idAsps, idFruizione);
  146.            
  147.             // preparo i campi
  148.             List<DataElement> dati = new ArrayList<>();
  149.             dati.add(ServletUtils.getDataElementForEditModeFinished());

  150.             DataElement deTestConnettivita = new DataElement();
  151.             deTestConnettivita.setType(DataElementType.TITLE);
  152.             deTestConnettivita.setLabel(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VERIFICA_CONNETTORE_TITLE);
  153.             dati.add(deTestConnettivita);
  154.            
  155.             if(aliases.size()==1 || alias!=null) {

  156.                 porteDelegateHelper.addDescrizioneVerificaConnettoreToDati(dati, null, labelConnettore, connettore, true,
  157.                         (CostantiControlStation.LABEL_VERIFICA_CONNETTORE_TUTTI_I_NODI.equals(alias)) ? aliases.get(0) : (alias!=null ? alias : aliases.get(0))
  158.                         );
  159.                
  160.                 if (!porteDelegateHelper.isEditModeInProgress()) {
  161.                
  162.                     List<String> aliasesForCheck = new ArrayList<>();
  163.                     if(aliases.size()==1) {
  164.                         aliasesForCheck.add(aliases.get(0));
  165.                     }
  166.                     else if(CostantiControlStation.LABEL_VERIFICA_CONNETTORE_TUTTI_I_NODI.equals(alias)) {
  167.                         aliasesForCheck.addAll(aliases);
  168.                     }
  169.                     else {
  170.                         aliasesForCheck.add(alias);
  171.                     }
  172.                                    
  173.                     boolean rilevatoErrore = false;
  174.                     String messagePerOperazioneEffettuata = "";
  175.                     int index = 0;
  176.                     for (String aliasForVerificaConnettore : aliasesForCheck) {
  177.                        
  178.                         String risorsa = null;
  179.                         if(connettoreRegistro) {
  180.                             risorsa = confCore.getJmxPdDConfigurazioneSistemaNomeRisorsaAccessoRegistroServizi(aliasForVerificaConnettore);
  181.                         }
  182.                         else {
  183.                             risorsa = confCore.getJmxPdDConfigurazioneSistemaNomeRisorsaConfigurazionePdD(aliasForVerificaConnettore);
  184.                         }
  185.                        
  186.                         StringBuilder bfExternal = new StringBuilder();
  187.                         String descrizione = confCore.getJmxPdDDescrizione(aliasForVerificaConnettore);
  188.                         if(aliases.size()>1) {
  189.                             if(index>0) {
  190.                                 bfExternal.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  191.                             }
  192.                             bfExternal.append(ConfigurazioneCostanti.LABEL_PARAMETRO_CONFIGURAZIONE_SISTEMA_NODO_CLUSTER).append(" ").append(descrizione).append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  193.                         }                      
  194.                         try{
  195.                             Boolean slowOperation = true; // altrimenti un eventuale connection timeout (es. 10 secondi) termina dopo il readTimeout associato all'invocazione dell'operazione via http check e quindi viene erroneamenteo ritornato un readTimeout
  196.                             String stato = confCore.getInvoker().invokeJMXMethod(aliasForVerificaConnettore, confCore.getJmxPdDConfigurazioneSistemaType(aliasForVerificaConnettore),
  197.                                     risorsa,
  198.                                     confCore.getJmxPdDConfigurazioneSistemaNomeMetodoCheckConnettoreById(aliasForVerificaConnettore),
  199.                                     slowOperation,
  200.                                     idConnettore+"");
  201.                             if(
  202.                                     JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO.equals(stato)
  203.                                     ||
  204.                                     (stato!=null && stato.startsWith(JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO_PREFIX))
  205.                                 ){
  206.                                 bfExternal.append(CostantiControlStation.LABEL_CONFIGURAZIONE_VERIFICA_CONNETTORE_EFFETTUATO_CON_SUCCESSO);
  207.                             }
  208.                             else{
  209.                                 rilevatoErrore = true;
  210.                                 bfExternal.append(CostantiControlStation.LABEL_CONFIGURAZIONE_VERIFICA_CONNETTORE_FALLITA);
  211.                                 if(stato!=null) {
  212.                                     if(stato.startsWith(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA)) {
  213.                                         bfExternal.append(stato.substring(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA.length()));
  214.                                     }
  215.                                     else {
  216.                                         bfExternal.append(stato);
  217.                                     }
  218.                                 }
  219.                             }
  220.                         }catch(Exception e){
  221.                             ControlStationCore.logError("Errore durante la verifica del connettore (jmxResource '"+risorsa+"') (node:"+aliasForVerificaConnettore+"): "+e.getMessage(),e);
  222.                             rilevatoErrore = true;
  223.                             String stato = e.getMessage();
  224.                             bfExternal.append(CostantiControlStation.LABEL_CONFIGURAZIONE_VERIFICA_CONNETTORE_FALLITA);
  225.                             if(stato.startsWith(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA)) {
  226.                                 bfExternal.append(stato.substring(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA.length()));
  227.                             }
  228.                             else {
  229.                                 bfExternal.append(stato);
  230.                             }
  231.                         }
  232.    
  233.                         if(messagePerOperazioneEffettuata.length()>0){
  234.                             messagePerOperazioneEffettuata+= org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE;
  235.                         }
  236.                         messagePerOperazioneEffettuata+= bfExternal.toString();
  237.                        
  238.                         index++;
  239.                     }
  240.                     if(messagePerOperazioneEffettuata!=null){
  241.                         if(rilevatoErrore)
  242.                             pd.setMessage(messagePerOperazioneEffettuata);
  243.                         else
  244.                             pd.setMessage(messagePerOperazioneEffettuata,Costanti.MESSAGE_TYPE_INFO);
  245.                     }
  246.    
  247.                     pd.disableEditMode();
  248.                    
  249.                 }
  250.                
  251.             }
  252.             else {
  253.                 porteDelegateHelper.addVerificaConnettoreSceltaAlias(aliases, dati);            
  254.             }
  255.            
  256.             pd.setLabelBottoneInvia(CostantiControlStation.LABEL_CONFIGURAZIONE_VERIFICA_CONNETTORE_BOTTONE);
  257.            
  258.             porteDelegateHelper.addVerificaConnettoreHidden(dati,
  259.                     id, idSoggFruitore, idAsps, idFruizione,
  260.                     idConnettore, accessoDaGruppi, connettoreRegistro);
  261.            
  262.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  263.                     idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  264.             pd.setDati(dati);

  265.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  266.             return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VERIFICA_CONNETTORE,   ForwardParams.OTHER(""));
  267.            
  268.         } catch (Exception e) {
  269.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  270.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VERIFICA_CONNETTORE, ForwardParams.OTHER(""));
  271.         }
  272.     }

  273. }