(file) Return to ServerShutdownClient.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Service

  1 martin 1.6 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.7 //
  3 martin 1.6 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.7 //
 10 martin 1.6 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.7 //
 17 martin 1.6 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.7 //
 20 martin 1.6 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.7 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.6 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.7 //
 28 martin 1.6 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <Pegasus/Common/Config.h>
 33            #include <Pegasus/Common/Constants.h>
 34            #include <Pegasus/Common/Logger.h>
 35            #include <Pegasus/Common/System.h>
 36            #include <Pegasus/Common/Tracer.h>
 37            #include <Pegasus/Client/CIMClient.h>
 38            #include <Service/ServerShutdownClient.h>
 39            
 40            PEGASUS_USING_STD;
 41            
 42            PEGASUS_NAMESPACE_BEGIN
 43            
 44            ServerShutdownClient::ServerShutdownClient(
 45                ServerRunStatus* serverRunStatus)
 46                : _serverRunStatus(serverRunStatus)
 47            {
 48            }
 49            
 50 kumpf  1.1 ServerShutdownClient::~ServerShutdownClient()
 51            {
 52            }
 53            
 54            //
 55            //  Waits until either the CIM Server has terminated, or the shutdown timeout
 56            //  has expired.  If the shutdown timeout has expired, and the CIM Server is
 57            //  still running, kills the cimserver process.
 58            //
 59            void ServerShutdownClient::_waitForTerminationOrTimeout(Uint32 maxWaitTime)
 60            {
 61                //
 62                //  If the CIM Server is still running, and the shutdown timeout has not
 63                //  expired, loop and wait one second until either the CIM Server has
 64                //  terminated, or the shutdown timeout has expired
 65                //
 66                Boolean running = _serverRunStatus->isServerRunning();
 67                while (running && (maxWaitTime > 0))
 68                {
 69                    System::sleep(1);
 70                    running = _serverRunStatus->isServerRunning();
 71 kumpf  1.1         maxWaitTime--;
 72                }
 73            
 74                //
 75                //  If the shutdown timeout has expired, and the CIM Server is still
 76                //  running, kill the cimserver process
 77                //
 78                if (running)
 79                {
 80                    Boolean wasKilled = _serverRunStatus->kill();
 81            
 82            #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 83 r.kieninger 1.5 || defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_SOLARIS) \
 84 kumpf       1.1 || defined (PEGASUS_OS_VMS)
 85                         if (wasKilled)
 86                         {
 87 kumpf       1.4             MessageLoaderParms parms(
 88 kumpf       1.1                 "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 89                                 "Shutdown timeout expired.  Forced shutdown initiated.");
 90 kumpf       1.4             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 91                                 parms);
 92 kumpf       1.1             cout << MessageLoader::getMessage(parms) << endl;
 93                             exit (0);
 94                         }
 95                 #endif
 96                     }
 97                 }
 98                 
 99                 void ServerShutdownClient::shutdown(Uint32 timeoutValue)
100                 {
101                     //
102                     // Create CIMClient object
103                     //
104                     CIMClient client;
105                 
106                     //
107                     // Get local host name
108                     //
109                     String hostStr = System::getHostName();
110                 
111                     //
112                     // open connection to CIMOM
113 kumpf       1.1     //
114                     try
115                     {
116                         client.connectLocal();
117                 
118                         //
119                         // set client timeout to 2 seconds
120                         //
121                         client.setTimeout(2000);
122                     }
123                     catch(Exception&)
124                     {
125                         MessageLoaderParms parms(
126                             "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
127                             "Unable to connect to CIM Server.  CIM Server may not be running.");
128                         PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
129                             PEGASUS_STD(endl);
130                         exit(1);
131                     }
132                 
133                     try
134 kumpf       1.1     {
135                         //
136                         // construct CIMObjectPath
137                         //
138                         String referenceStr = "//";
139                         referenceStr.append(hostStr);
140                         referenceStr.append("/");
141                         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
142                         referenceStr.append(":");
143                         referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
144                         CIMObjectPath reference(referenceStr);
145                 
146                         //
147                         // issue the invokeMethod request on the shutdown method
148                         //
149                         Array<CIMParamValue> inParams;
150                         Array<CIMParamValue> outParams;
151                 
152                         // set force option to true for now
153                         inParams.append(CIMParamValue("force",
154                             CIMValue(Boolean(true))));
155 kumpf       1.1 
156                         inParams.append(CIMParamValue("timeout",
157                             CIMValue(Uint32(timeoutValue))));
158                 
159                         CIMValue retValue = client.invokeMethod(
160                             PEGASUS_NAMESPACENAME_SHUTDOWN,
161                             reference,
162                             "shutdown",
163                             inParams,
164                             outParams);
165                     }
166                     catch(CIMException& e)
167                     {
168                         //l10n - TODO
169 kumpf       1.3         MessageLoaderParms shutdownFailedMsgParms(
170                             "src.Server.cimserver.SHUTDOWN_FAILED",
171                             "Error in server shutdown: ");
172                         PEGASUS_STD(cerr) << MessageLoader::getMessage(shutdownFailedMsgParms);
173 kumpf       1.1         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
174                         {
175                             //
176                             // Repository may be empty.
177                             //
178                             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
179 kumpf       1.4                 MessageLoaderParms(
180                                     "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
181                                     "Error in server shutdown: The repository may be empty."));
182 kumpf       1.3             MessageLoaderParms parms(
183                                 "src.Server.cimserver.REPOSITORY_EMPTY",
184                                 "The repository may be empty.");
185 kumpf       1.1             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
186                                 PEGASUS_STD(endl);
187                         }
188                         else
189                         {
190                             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
191 kumpf       1.4                 MessageLoaderParms(
192                                     "src.Server.cimserver.SHUTDOWN_FAILED",
193                                     "Error in server shutdown: $0", e.getMessage()));
194 kumpf       1.1             PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
195                         }
196                 
197                         // Kill the cimserver process
198                         if (_serverRunStatus->kill())
199                         {
200                             MessageLoaderParms parms(
201                                 "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
202                                 "Forced shutdown initiated.");
203 kumpf       1.4             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
204                                 parms);
205 kumpf       1.1             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
206                                 PEGASUS_STD(endl);
207                         }
208                         exit(1);
209                     }
210                     catch(Exception&)
211                     {
212                         //
213                         // This may mean that the CIM Server has terminated, causing this
214                         // client to get a "Empty HTTP response message" exception.  It may
215                         // also mean that the CIM Server is taking longer than 2 seconds
216                         // (client timeout value) to terminate, causing this client to
217                         // timeout with a "connection timeout" exception.
218                         //
219                         //  Wait until either the CIM Server has terminated, or the shutdown
220                         //  timeout has expired.  If the timeout has expired and the CIM Server
221                         //  is still running, kill the cimserver process.
222                         //
223                         _waitForTerminationOrTimeout(timeoutValue - 2);
224                         return;
225                     }
226 kumpf       1.1 
227                     //
228                     //  InvokeMethod succeeded.
229                     //  Wait until either the CIM Server has terminated, or the shutdown
230                     //  timeout has expired.  If the timeout has expired and the CIM Server
231                     //  is still running, kill the cimserver process.
232                     //
233                     _waitForTerminationOrTimeout(timeoutValue);
234                 }
235                 
236                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2