Arcane  v3.15.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
FlexLMTools.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* FlexLMTools.cc (C) 2000-2025 */
9/* */
10/* Implémentation d'une interface pour les outils FlexLM. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/impl/FlexLMTools.h"
14
15/* L'interface à FlexNet ici employée est une surcouche à FlexNet de TAD
16 * prenant en charge par exemple le rappel périodique du contrôle de licence.
17 * Le recheck par défaut est tous les 120s (cf setCheckInterval)
18 */
19
20#define FLEXLMAPI_IS_STATIC_LIBRARY
21#define c_plusplus
22#include <FlexlmAPI.h>
23
24#include "arcane/IParallelSuperMng.h"
25#include "arcane/utils/FatalErrorException.h"
26#include "arcane/utils/TraceInfo.h"
27#include "arcane/utils/StringBuilder.h"
28#include "arcane/utils/Array.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33ARCANE_BEGIN_NAMESPACE
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38LicenseErrorException::
39LicenseErrorException(const String& where)
40: Exception("LicenseError",where)
41{
42 setCollective(true);
43}
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48LicenseErrorException::
49LicenseErrorException(const String& where,const String& message)
50: Exception("LicenseError",where,message)
51{
52 setCollective(true);
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58LicenseErrorException::
59LicenseErrorException(const TraceInfo& where)
60: Exception("LicenseError",where)
61{
62 setCollective(true);
63}
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68LicenseErrorException::
69LicenseErrorException(const TraceInfo& where,const String& message)
70: Exception("LicenseError",where,message)
71{
72 setCollective(true);
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78void LicenseErrorException::
79explain(std::ostream& m) const
80{
81 m << "Licensing error occured.\n"
82 << "Excution stopped.\n";
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88void LicenseErrorException::
89write(std::ostream& o) const
90{
91 o << name() << "\n";
92#ifdef ARCANE_DEBUG
93 o << "Exception thrown in: '" << where() << "\n";
94#endif /* ARCANE_DEBUG */
95 if (!message().null())
96 o << "Message: " << message() << '\n';
97 this->explain(o);
98#ifdef ARCANE_DEBUG
99 String st = stackTrace().toString();
100 if (!st.null()){
101 o << "\nCall stack:\n";
102 o << st << '\n';
103 }
104#endif /* ARCANE_DEBUG */
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113FlexLMMng* FlexLMMng::m_instance = NULL ;
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118FlexLMMng::
119FlexLMMng()
120 : m_parallel_super_mng(NULL)
121{
122 ;
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
130instance()
131{
132 if(m_instance==NULL)
133 m_instance = new FlexLMMng() ;
134 return m_instance ;
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140void
143{
144 if (m_parallel_super_mng != NULL)
145 throw LicenseErrorException(A_FUNCINFO,"FlexLMMng already initialized");
146
147 // Test en mode master check le droit de décentralisé le contrôle
148 m_is_master = (parallel_super_mng->commRank() == 0);
149
150 // Marque l'initialisation effective; on peut maintenant utiliser le système de licence
151 m_parallel_super_mng = parallel_super_mng;
152
154#ifndef ARCANE_TEST_RLM
155 license_tool.checkLicense(ArcaneFeatureModel::ArcaneCore,true); // do_fatal=true
156#else
157 license_tool.checkLicense(ArcaneFeatureModel::Arcane,true); // do_fatal=true
158#endif
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164void
166setCheckInterval(const Integer t)
167{
168 // Toutes les spécificités sont gérées dans la fonction
170}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175bool
177checkLicense(const String name, const Real version, const bool do_fatal) const
178{
179 if (m_parallel_super_mng == NULL)
180 throw LicenseErrorException(A_FUNCINFO,"FlexLMMng not initialized");
181
182 Integer test = 0;
183 if (m_is_master)
184 test = license_test((char*)name.localstr(),(char*)String::format("{0}",version).localstr());
185 m_parallel_super_mng->broadcast(IntegerArrayView(1,&test),0);
186
187 if (test != 0 && do_fatal)
188 throw LicenseErrorException(A_FUNCINFO,String::format("Checking feature {0} (v{1}) has failed\nFeature info: {2}",name,version,featureInfo(name,version)));
189 return (test == 0);
190}
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194
195void
197getLicense(const String name, const Real version, Integer nb_licenses)
198{
199 if (m_parallel_super_mng == NULL)
200 throw LicenseErrorException(A_FUNCINFO,"FlexLMMng not initialized");
201
202 Integer error = 0;
203 if (m_is_master)
204 {
205 m_features[name] += nb_licenses ;
206 for(Integer i=0;i<nb_licenses;++i)
207 error += license_begin_rc((char*)name.localstr(), (char*)String::format("{0}",version).localstr()) ;
208 }
209 m_parallel_super_mng->broadcast(IntegerArrayView(1,&error),0);
210 if (error != 0)
211 throw LicenseErrorException(A_FUNCINFO,String::format("Cannot checkout {0} license{1} for feature {2} (v{3})\nFeature info: {4}",nb_licenses,((nb_licenses>1)?"s":""),name,version,featureInfo(name,version)));
212}
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217void
219releaseLicense(const String name, Integer nb_licenses)
220{
221 if (m_parallel_super_mng == NULL)
222 throw LicenseErrorException(A_FUNCINFO,"FlexLMMng not initialized");
223
224 if (nb_licenses == 0)
225 return;
226
227 if (m_is_master)
228 {
229 FeatureMapType::iterator finder = m_features.find(name);
230
231 // Pas de code d'erreur pour compatibilité avec la précédente version
232 if (finder == m_features.end()) return;
233
234 Integer & nb_allocated_licenses = finder->second;
236 for(Integer i=0;i<nb_licenses;++i)
237 license_end_no_quit((char*)name.localstr()) ;
238
241 }
242}
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247void
250{
251 if (m_parallel_super_mng == NULL)
252 return;
253
254 if (m_is_master)
255 {
256 for(FeatureMapType::iterator iter = m_features.begin(); iter!=m_features.end(); ++iter)
257 {
258 const String name = (*iter).first ;
259 Integer nb_licenses = (*iter).second ;
260 for(Integer i=0; i<nb_licenses; ++i)
261 license_end_no_quit((char*) name.localstr()) ;
262 (*iter).second = 0 ;
263 }
264 }
265}
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
269
270String
272featureInfo(const String name, const Real version) const
273{
274 String info;
275 if (m_is_master)
276 {
278 if (license_test((char*)name.localstr(),(char*)String::format("{0}",version).localstr()) == 0)
279 {
280 Integer count = 0;
281 char ** users = get_user_list((char*)name.localstr());
282 while(users[count]) { info_builder += String::format("{0} ",users[count++]); }
283 if (count == 0) {
284 info_builder = String::format("no declared user");
285 } else {
286 info_builder = String::format("Used by {0} user{1} : ",count,((count>1)?"s":""),info_builder.toString());
287 }
288
289 // license_test_expiration semble buggué : segfault
290 // int expiration_code = license_test_expiration((char*)name.localstr());
291 // info_builder += String::format("\nExpiration Code {0}",expiration_code);
292
293 info = info_builder.toString();
294 }
295 else
296 {
297 info = "Unknown feature";
298 }
299 }
300
301 // remplace m_parallel_super_mng->broadcastString(info,0) qui n'existe pas dans IParallelSuperMng
302 Integer len_info[1] = { info.utf8().size() };
303 m_parallel_super_mng->broadcast(IntegerArrayView(1,len_info),0);
304 if (m_is_master) {
306 m_parallel_super_mng->broadcast(utf8_array,0);
307 } else {
309 m_parallel_super_mng->broadcast(utf8_array,0);
310 info = String::fromUtf8(utf8_array);
311 }
312
313 return info;
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
319const String ArcaneFeatureModel::m_arcane_feature_name[] =
320 {
321#ifndef ARCANE_TEST_RLM
322 "ArcaneCore",
323#else
324 "Arcane",
325#endif
326 };
327
328/*---------------------------------------------------------------------------*/
329/*---------------------------------------------------------------------------*/
330
331ARCANE_END_NAMESPACE
332
333/*---------------------------------------------------------------------------*/
334/*---------------------------------------------------------------------------*/
FlexLM manager.
Definition FlexLMTools.h:72
static FlexLMMng * instance()
Accès au singleton.
FlexLMMng()
Constructeur.
void getLicense(const String name, const Real version, Integer nb_licenses=1)
Demande l'allocation de.
bool checkLicense(const String name, const Real version, bool do_fatal=true) const
Teste la présence d'une fonctionnalité statique.
void setCheckInterval(const Integer t=120)
Définit une nouvelle périodicité du contrôle des licences.
void init(IParallelSuperMng *parallel_super_mng)
Initialise le gestionnaire de licences.
void releaseAllLicenses()
Relache toutes les licences allouées.
bool m_is_master
Cet host est il le maître des contrôles ?
void releaseLicense(const String name, Integer nb_licenses=0)
Relache les licences de la fonctionnalité
String featureInfo(const String name, const Real version) const
Return info on feature.
Classe abstraite du superviseur de parallélisme.
virtual void broadcast(ByteArrayView send_buf, Integer process_id)=0
Envoie un tableau de valeurs sur tous les processus Cette opération synchronise le tableau de valeur ...
Exception de licence.
Definition FlexLMTools.h:42
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:149
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Constructeur de chaîne de caractère unicode.
Chaîne de caractères unicode.
ByteConstArrayView utf8() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Definition String.cc:275
bool null() const
Retourne true si la chaîne est nulle.
Definition String.cc:304
Vecteur 1D de données avec sémantique par valeur (style STL).
ArrayView< Integer > IntegerArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:547