1 #include "orbsvcs/Log_Macros.h"
4 #include "tao/PortableServer/PortableServer.h"
5 #include "tao/PortableServer/ForwardRequestC.h"
8 #include "tao/Profile.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/Read_Buffer.h"
11 #include "ace/OS_NS_strings.h"
12 #include "ace/os_include/os_netdb.h"
13 #include "ace/OS_NS_unistd.h"
15 TAO_IMR_i::TAO_IMR_i ()
19 imr_ (ImplementationRepository::Administration::_nil ()),
25 TAO_IMR_i::~TAO_IMR_i ()
32 if (this->op_
.get () == 0)
34 ORBSVCS_ERROR ((LM_ERROR
, "Unknown operation"));
35 return TAO_IMR_Op::UNKNOWN
;
38 return this->op_
->run ();
42 TAO_IMR_i::init (int argc
, ACE_TCHAR
**argv
)
47 const char *exception_message
= "Null Message";
52 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
, "tao_imr_i");
54 // Parse command line and verify parameters.
55 if (this->parse_args () == -1)
58 // Get the ImplRepo object
59 CORBA::Object_var obj
=
60 orb_
->resolve_initial_references ("ImplRepoService");
62 if (CORBA::is_nil (obj
.in ()))
64 ORBSVCS_ERROR ((LM_ERROR
, "Unable to resolve the ImR.\n"));
68 exception_message
= "While narrowing ImR";
71 ImplementationRepository::Administration::_narrow (obj
.in ());
73 if (CORBA::is_nil (imr_
.in ()))
75 ORBSVCS_ERROR ((LM_ERROR
, "Unable to narrow the ImR.\n"));
79 this->op_
->set_imr (this->imr_
.in ());
81 catch (const CORBA::Exception
& ex
)
83 ORBSVCS_ERROR ((LM_ERROR
, "TAO_IMR_i::init - %C\n", exception_message
));
84 ex
._tao_print_exception ("Exception");
92 // Go through and figure out which operation we should do.
95 TAO_IMR_i::parse_args ()
97 // Make sure one command was given
100 ORBSVCS_ERROR((LM_ERROR
, "Error: No operation specified.\n"));
101 this->print_usage ();
105 this->op_
.reset (TAO_IMR_Op::make_op (this->argv_
[1]));
107 // Check for unrecognized operation
109 if (this->op_
.get () == 0)
111 ORBSVCS_ERROR((LM_ERROR
, "Error: Unknown operation '%s'.\n", this->argv_
[1]));
112 this->print_usage ();
116 // Adjust argc and argv so only the command specific args are passed
117 return this->op_
->parse (this->argc_
- 1, this->argv_
+ 1);
121 // Print out information about all operations.
124 TAO_IMR_i::print_usage ()
126 ORBSVCS_ERROR ((LM_ERROR
, "Usage: tao_imr [options] command [command-arguments]\n"
127 " where [options] are ORB options\n"
128 " where command is one of the following:\n"
129 " start Start a server through the ImR\n"
130 " add Add an entry to the ImR\n"
131 " autostart Activates all AUTO_START servers\n"
132 " ior Creates a simplified IOR\n"
133 " list List the entries in the ImR\n"
134 " remove Remove an entry from the ImR\n"
135 " shutdown Shut down a server through the ImR\n"
136 " shutdown-repo Shut down the ImR\n"
137 " update Update an entry in the ImR\n"
138 " where [command-arguments] depend on the command\n"));
142 // Factory for operations
145 TAO_IMR_Op::make_op (const ACE_TCHAR
*op_name
)
147 if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("activate")) == 0)
149 ORBSVCS_ERROR((LM_ERROR
, "Warning: The activate option has been renamed to start.\n"));
150 return new TAO_IMR_Op_Activate ();
152 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("start")) == 0)
153 return new TAO_IMR_Op_Activate ();
154 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("add")) == 0)
155 return new TAO_IMR_Op_Register (true);
156 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("autostart")) == 0)
157 return new TAO_IMR_Op_Autostart();
158 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("ior")) == 0)
159 return new TAO_IMR_Op_IOR();
160 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("kill")) == 0)
161 return new TAO_IMR_Op_Kill ();
162 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("link")) == 0)
163 return new TAO_IMR_Op_Link ();
164 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("list")) == 0)
165 return new TAO_IMR_Op_List ();
166 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("remove")) == 0)
167 return new TAO_IMR_Op_Remove ();
168 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("shutdown")) == 0)
169 return new TAO_IMR_Op_Shutdown ();
170 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("shutdown-repo")) == 0)
171 return new TAO_IMR_Op_ShutdownRepo ();
172 else if (ACE_OS::strcasecmp (op_name
, ACE_TEXT ("update")) == 0)
173 return new TAO_IMR_Op_Register (false);
179 TAO_IMR_Op::~TAO_IMR_Op ()
185 TAO_IMR_Op::set_imr (ImplementationRepository::Administration_ptr imr
)
191 TAO_IMR_Op::display_server_information (const ImplementationRepository::ServerInformation
&info
)
193 // Figure out what the activation string is.
194 const char *act
= "UNKNOWN STARTUP";
195 if (info
.startup
.activation
== ImplementationRepository::NORMAL
)
197 else if (info
.startup
.activation
== ImplementationRepository::MANUAL
)
199 else if (info
.startup
.activation
== ImplementationRepository::PER_CLIENT
)
201 else if (info
.startup
.activation
== ImplementationRepository::AUTO_START
)
204 // Print out information
205 ORBSVCS_DEBUG ((LM_DEBUG
, "Server <%C>\n", info
.server
.in ()));
207 const char * locked_out
= "";
209 int limit
= info
.startup
.start_limit
;
210 if (info
.startup
.start_limit
< 0)
213 locked_out
= " Locked Out\n";
216 ORBSVCS_DEBUG ((LM_DEBUG
, " Activator: %C\n", info
.startup
.activator
.in ()));
218 ORBSVCS_DEBUG ((LM_DEBUG
, " Command Line: "));
219 if (ACE_OS::strlen(info
.startup
.command_line
.in ()) <= ACE_MAXLOGMSGLEN
)
221 ORBSVCS_DEBUG ((LM_DEBUG
, "%C", info
.startup
.command_line
.in ()));
225 char *cl
= const_cast<char *>(info
.startup
.command_line
.in ());
229 size_t len
= ACE_OS::strlen(cl
);
230 if (len
> ACE_MAXLOGMSGLEN
)
232 len
= ACE_MAXLOGMSGLEN
;
236 ORBSVCS_DEBUG ((LM_DEBUG
, "%C", cl
));
241 ORBSVCS_DEBUG ((LM_DEBUG
, "\n"));
242 ORBSVCS_DEBUG ((LM_DEBUG
, " Working Directory: %s\n", info
.startup
.working_directory
.in ()));
243 ORBSVCS_DEBUG ((LM_DEBUG
, " Activation Mode: %C\n", act
));
244 ORBSVCS_DEBUG ((LM_DEBUG
, " Number of retries: %d\n%C", limit
- 1, locked_out
));
247 for (CORBA::ULong i
= 0; i
< info
.startup
.environment
.length (); ++i
)
248 ORBSVCS_DEBUG ((LM_DEBUG
, "Environment Variable: %C=%C\n",
249 info
.startup
.environment
[i
].name
.in (),
250 info
.startup
.environment
[i
].value
.in ()));
252 if (info
.startup
.activation
== ImplementationRepository::PER_CLIENT
)
253 ORBSVCS_DEBUG ((LM_DEBUG
,
254 " No running info available for PER_CLIENT mode\n"));
255 else if (ACE_OS::strlen (info
.partial_ior
.in ()) > 0)
256 ORBSVCS_DEBUG ((LM_DEBUG
,
257 " Running at endpoint: %C\n",
258 info
.partial_ior
.in ()));
259 else // I am assuming that a blank partial_ior means currently not running.
260 ORBSVCS_DEBUG ((LM_DEBUG
,
261 " Not currently running\n"));
263 ORBSVCS_DEBUG ((LM_DEBUG
, "\n"));
266 TAO_IMR_Op_List::TAO_IMR_Op_List ()
267 : verbose_server_information_ (0)
268 , list_only_active_servers_ (0)
275 TAO_IMR_Op_Register::TAO_IMR_Op_Register (bool is_add
)
277 , set_command_line_ (false)
278 , set_environment_vars_(false)
279 , set_working_dir_ (false)
280 , set_activation_ (false)
281 , activation_(ImplementationRepository::NORMAL
)
282 , set_retry_count_(false)
284 , set_activator_ (false)
290 TAO_IMR_Op_Activate::print_usage ()
292 ORBSVCS_ERROR ((LM_ERROR
,
293 "Starts a server using its registered Activator.\n\n"
294 "Usage: tao_imr [options] start <name>\n"
295 " where [options] are ORB options\n"
296 " where <name> is the name of a registered POA.\n"
298 " -h Displays this\n"));
302 TAO_IMR_Op_Activate::parse (int argc
, ACE_TCHAR
**argv
)
304 // Check for enough arguments (we need at least one for the server name)
307 this->print_usage ();
311 // Skip both the program name and the "activate" command
312 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hq"));
314 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
317 while ((c
= get_opts ()) != -1)
325 this->print_usage ();
328 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
329 this->print_usage ();
337 TAO_IMR_Op_Autostart::print_usage ()
339 ORBSVCS_ERROR ((LM_ERROR
, "Usage: tao_imr [options] autostart\n"
340 " where [options] are ORB options\n"
341 " -h Displays this\n"));
345 TAO_IMR_Op_Autostart::parse (int argc
, ACE_TCHAR
**argv
)
347 // Skip the "autostart" command
348 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("h"));
352 while ((c
= get_opts ()) != -1)
356 case 'h': // display help
357 this->print_usage ();
360 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
361 this->print_usage ();
369 TAO_IMR_Op_IOR::print_usage ()
371 ORBSVCS_ERROR ((LM_ERROR
, "Creates an IOR for a server that is registered with the IMR and uses\n"
372 "the InterOperable Naming Service. Please see the documentation for\n"
373 "more information on which server configurations work with this command.\n"
375 "Usage: tao_imr [options] ior <object_key> [command-arguments]\n"
376 " where [options] are ORB options\n"
377 " where <object_key> matches the simple key bound in the server IORTable.\n"
378 " where [command-arguments] can be\n"
379 " -f filename filename to output the IOR to\n"
380 " -h Displays this\n"));
384 TAO_IMR_Op_IOR::parse (int argc
, ACE_TCHAR
**argv
)
386 // Check for enough arguments (we need at least one for the server name)
389 this->print_usage ();
393 // Skip both the program name and the "ior" command
394 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hf:"));
396 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
397 if (this->server_name_
.length() == 0 || this->server_name_
[0] == '-')
399 ORBSVCS_ERROR((LM_ERROR
, "ERROR : name is required.\n"));
400 this->print_usage ();
406 while ((c
= get_opts ()) != -1)
410 case 'f': // File name
411 this->filename_
= get_opts
.opt_arg ();
413 case 'h': // display help
414 this->print_usage ();
417 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
418 this->print_usage ();
426 TAO_IMR_Op_Kill::print_usage ()
428 ORBSVCS_ERROR ((LM_ERROR
,
429 "Sends a signal to the designated process\n\n"
430 "The process must have been started by the ImR\n"
431 "and may not use per-client activation\n"
432 "Usage: tao_imr [options] kill [name] [command-arguments]\n"
433 " where [options] are ORB options\n"
434 " where [name] is the registered POA name the peers link to\n"
435 " where [command-arguments] can be\n"
437 " -s signum default 9, the signal to be sent to the\n"
438 " process for named server\n"));
442 TAO_IMR_Op_Kill::parse (int argc
, ACE_TCHAR
**argv
)
446 if (argc
> 1 && argv
[1][0] != '-')
448 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
453 // Skip both the program name and the "list" command
454 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:hq"), server_flag
);
458 while ((c
= get_opts ()) != -1)
463 this->signum_
= ACE_OS::strtol (get_opts
.opt_arg (), 0, 10);
468 case 'h': // display help
469 this->print_usage ();
472 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
473 this->print_usage ();
481 TAO_IMR_Op_Link::print_usage ()
483 ORBSVCS_ERROR ((LM_ERROR
, "Links multiple POAs to a single executable\n"
485 "Usage: tao_imr [options] link [name] [command-arguments]\n"
486 " where [options] are ORB options\n"
487 " where [name] is the registered POA name the peers link to\n"
488 " where [command-arguments] can be\n"
489 " -p peers provides a comma separated list of additional POAs that are\n"
490 " part of the same executable. -p may be repeated\n"));
494 TAO_IMR_Op_Link::parse (int argc
, ACE_TCHAR
**argv
)
498 if (argc
> 1 && argv
[1][0] != '-')
500 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
504 // Skip both the program name and the "list" command
505 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:h"), server_flag
);
509 while ((c
= get_opts ()) != -1)
513 case 'p': //list of peers
515 char *arg
= ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ());
516 CORBA::ULong last
= this->peers_
.length ();
517 CORBA::ULong num
= 0;
522 c
= ACE_OS::strchr (c
, ',');
527 this->peers_
.length (num
);
530 if ((c
= ACE_OS::strchr (arg
, ',')) != 0)
532 this->peers_
[last
++] = CORBA::string_dup (arg
);
538 case 'h': // display help
539 this->print_usage ();
542 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
543 this->print_usage ();
551 TAO_IMR_Op_List::print_usage ()
553 ORBSVCS_ERROR ((LM_ERROR
, "Lists all or one of the servers in the Implementation Repository\n"
555 "Usage: tao_imr [options] list [name] [command-arguments]\n"
556 " where [options] are ORB options\n"
557 " where [name] is the optional server name to search for\n"
558 " where [command-arguments] can be\n"
559 " -v Verbose: Displays more info for each server when\n"
560 " displaying more than one server\n"
561 " -a List only servers that are determined to be active\n"
562 " -n <count> Request no more than <count> entries and use an iterator\n"
563 " -h Displays this\n"));
567 TAO_IMR_Op_List::parse (int argc
, ACE_TCHAR
**argv
)
571 if (argc
> 1 && argv
[1][0] != '-')
573 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
577 // Skip both the program name and the "list" command
578 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("ahn:tv"), server_flag
);
582 while ((c
= get_opts ()) != -1)
586 case 'v': // verbose server display
587 this->verbose_server_information_
= 1;
593 this->list_only_active_servers_
= 1;
596 this->how_many_
= ACE_OS::atoi (get_opts
.opt_arg ());
598 case 'h': // display help
599 this->print_usage ();
602 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
603 this->print_usage ();
611 TAO_IMR_Op_Remove::print_usage ()
613 ORBSVCS_ERROR ((LM_ERROR
, "Removes a server entry\n"
615 "Usage: tao_imr [options] remove <name> [-f [-s <signum>]]\n"
616 " where [options] are ORB options\n"
617 " -f forces shutdown or kill of a running server"
618 " -s specifies a signal for killing the server, if it is 0, a shutdown will be used"
619 " where <name> is the POA name used by the server object\n"
620 " -h Displays this\n"));
624 TAO_IMR_Op_Remove::parse (int argc
, ACE_TCHAR
**argv
)
626 // Check for enough arguments (we need at least one for the server name)
629 this->print_usage ();
632 this->force_
= false;
635 // Skip both the program name and the "remove" command
636 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hfs:"));
638 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
641 while ((c
= get_opts ()) != -1)
646 this->print_usage ();
652 this->signum_
= ACE_OS::strtol (get_opts
.opt_arg (), 0, 10);
655 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
656 this->print_usage ();
665 TAO_IMR_Op_Shutdown::print_usage ()
667 ORBSVCS_ERROR ((LM_ERROR
,
668 "Shuts down a server\n\n"
669 "Usage: tao_imr [options] shutdown <name>\n"
670 " where [options] are ORB options\n"
671 " where <name> is the name of the server object\n"
673 " -h Displays this\n"));
677 TAO_IMR_Op_Shutdown::parse (int argc
, ACE_TCHAR
**argv
)
679 // Check for enough arguments (we need at least one for the server name)
682 this->print_usage ();
686 // Skip both the program name and the "shutdown" command
687 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hq"));
689 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
692 while ((c
= get_opts ()) != -1)
700 this->print_usage ();
703 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
704 this->print_usage ();
711 TAO_IMR_Op_ShutdownRepo::TAO_IMR_Op_ShutdownRepo()
717 TAO_IMR_Op_ShutdownRepo::print_usage ()
719 ORBSVCS_ERROR ((LM_ERROR
, "Shuts down the ImR\n"
721 "Usage: tao_imr [options] shutdown-repo [-a]\n"
722 " where [options] are ORB options\n"
723 " Specify -a to also shutdown any registered ImR Activators.\n"
724 " -h Displays this\n"));
728 TAO_IMR_Op_ShutdownRepo::parse (int argc
, ACE_TCHAR
**argv
)
730 // Check for enough arguments (we need at least one for the server name)
733 this->print_usage ();
737 // Skip both the program name and the "shutdown-repo" command
738 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("ha"));
742 while ((c
= get_opts ()) != -1)
747 this->print_usage ();
753 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
754 this->print_usage ();
763 TAO_IMR_Op_Register::addenv (ACE_TCHAR
*opt
)
765 CORBA::ULong length
= this->environment_vars_
.length ();
766 // Increase the length of the sequence
767 this->environment_vars_
.length (length
+ 1);
768 ACE_TString
tokens (opt
);
769 size_t index
= tokens
.find (ACE_TEXT("="));
770 // Insert at position length since that is our new element
771 this->environment_vars_
[length
].name
=
772 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(tokens
.substr (0, index
).c_str ()));
773 this->environment_vars_
[length
].value
=
774 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(tokens
.substr (index
+ 1).c_str ()));
778 TAO_IMR_Op_Register::print_usage ()
780 ORBSVCS_ERROR ((LM_ERROR
,
781 "Adds/Updates a server entry\n\n"
782 "Usage: tao_imr [options] <add|update> <name> [command-arguments]\n"
783 " where [options] are ORB options\n"
784 " where <name> is the POA name used by the server object\n"
785 " where [command-arguments] can be\n"
786 " -h Displays this\n"
788 " -l Activator name.\n"
789 " -c command Startup command\n"
790 " -w dir Working directory\n"
791 " -e name=value Set environment variables\n"
792 " -a mode Set activate mode (NORMAL|MANUAL|PER_CLIENT|AUTO_START)\n"
793 " -r count Set the startup/ping retry count to count\n"));
797 TAO_IMR_Op_Register::parse (int argc
, ACE_TCHAR
**argv
)
799 // Check for enough arguments (we need at least one for the server name)
802 ORBSVCS_ERROR((LM_ERROR
, "Error: Must supply at least a server name.\n"));
803 this->print_usage ();
807 // Skip both the program name and the "update" command
808 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hqc:w:a:e:r:R:l:"));
810 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(argv
[1]);
813 while ((c
= get_opts ()) != -1)
817 case 'c': // Command line arguments
818 this->set_command_line_
= true;
819 this->command_line_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
821 case 'e': // set environment variables
822 this->set_environment_vars_
= true;
823 this->addenv( get_opts
.opt_arg () );
825 case 'w': // Working Directory
826 this->set_working_dir_
= true;
827 this->working_dir_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
829 case 'a': // Activation Mode
830 this->set_activation_
= true;
831 if (ACE_OS::strcasecmp (get_opts
.opt_arg (), ACE_TEXT("NORMAL")) == 0)
832 this->activation_
= ImplementationRepository::NORMAL
;
833 else if (ACE_OS::strcasecmp (get_opts
.opt_arg (), ACE_TEXT("MANUAL")) == 0)
834 this->activation_
= ImplementationRepository::MANUAL
;
835 else if (ACE_OS::strcasecmp (get_opts
.opt_arg (), ACE_TEXT("PER_CLIENT")) == 0)
836 this->activation_
= ImplementationRepository::PER_CLIENT
;
837 else if (ACE_OS::strcasecmp (get_opts
.opt_arg (), ACE_TEXT("AUTO_START")) == 0)
838 this->activation_
= ImplementationRepository::AUTO_START
;
840 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
841 "Unknown Activation Mode <%s>.\n",
842 get_opts
.opt_arg ()),
846 case 'R': // startup/ping Retry Count
848 this->set_retry_count_
= true;
849 int rc
= ACE_OS::atoi(get_opts
.optarg
);
851 this->retry_count_
= rc
;
854 case 'l': /// hostname of the activator
855 this->activator_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.optarg
);
856 this->set_activator_
= true;
861 case 'h': // display help
862 this->print_usage ();
865 ORBSVCS_ERROR((LM_ERROR
, "ERROR : Unknown option '%c'\n", (char) c
));
866 this->print_usage ();
874 // ============================================================================
879 TAO_IMR_Op_Activate::run ()
881 ACE_ASSERT(! CORBA::is_nil(imr_
));
884 this->imr_
->activate_server (this->server_name_
.c_str ());
887 ORBSVCS_DEBUG ((LM_DEBUG
,
888 "Successfully Activated server <%C>\n",
889 this->server_name_
.c_str ()));
892 catch (const ImplementationRepository::CannotActivate
& ex
)
896 ORBSVCS_ERROR ((LM_ERROR
,
897 "Cannot activate server <%C> reason <%C>\n",
898 this->server_name_
.c_str (),
901 return TAO_IMR_Op::CANNOT_ACTIVATE
;
903 catch (const ImplementationRepository::NotFound
&)
907 ORBSVCS_ERROR ((LM_ERROR
,
908 "Could not find server <%C>.\n",
909 this->server_name_
.c_str ()));
911 return TAO_IMR_Op::NOT_FOUND
;
913 catch (const PortableServer::ForwardRequest
&)
917 catch (const CORBA::Exception
& ex
)
921 ex
._tao_print_exception ("Activating Server");
923 return TAO_IMR_Op::UNKNOWN
;
926 return TAO_IMR_Op::NORMAL
;
930 TAO_IMR_Op_Autostart::run ()
932 ACE_ASSERT(! CORBA::is_nil (imr_
));
934 ImplementationRepository::ServerInformationList_var server_list
;
935 ImplementationRepository::ServerInformationIterator_var server_iter
;
944 ACE_ASSERT(CORBA::is_nil (server_iter
.in ()));
946 CORBA::ULong len
= server_list
->length ();
947 for (CORBA::ULong i
= 0; i
< len
; ++i
)
951 this->imr_
->activate_server (server_list
[i
].server
.in ());
953 catch (const CORBA::Exception
& ex
)
955 ex
._tao_print_exception (server_list
[i
].server
.in ());
960 catch (const CORBA::Exception
& ex
)
962 ex
._tao_print_exception ("autostart");
963 return TAO_IMR_Op::UNKNOWN
;
966 return TAO_IMR_Op::NORMAL
;
970 TAO_IMR_Op_IOR::run ()
972 ACE_ASSERT (! CORBA::is_nil(imr_
));
974 // Create a corbaloc string
975 // Todo : Most of this logic duplicates that in the POA.cpp
978 if (CORBA::is_nil (this->imr_
)
979 || !this->imr_
->_stubobj ()
980 || !this->imr_
->_stubobj ()->profile_in_use ())
982 ORBSVCS_ERROR_RETURN ((
984 ACE_TEXT ("Invalid ImR IOR.\n")
988 CORBA::String_var imr_str
=
989 this->imr_
->_stubobj ()->
990 profile_in_use ()->to_string ();
992 // Search for "corbaloc:" alone, without the protocol. This code
993 // should be protocol neutral.
994 const char corbaloc
[] = "corbaloc:";
995 char *pos
= ACE_OS::strstr (imr_str
.inout (), corbaloc
);
999 ORBSVCS_ERROR_RETURN ((LM_ERROR
, "Could not parse IMR IOR.\n"), -1);
1003 pos
= ACE_OS::strchr (pos
+ sizeof (corbaloc
), ':');
1004 pos
= ACE_OS::strchr (pos
+ 1,
1005 this->imr_
->_stubobj ()->profile_in_use ()->object_key_delimiter ());
1009 *(pos
+ 1) = 0; // Crop the string
1013 ORBSVCS_ERROR_RETURN ((LM_ERROR
, "Could not parse IMR IOR.\n"), -1);
1016 ACE_CString
ior (imr_str
.in ());
1019 const char jacorb
[] = "JACORB:";
1020 const char *posjacorb
= ACE_OS::strstr (server_name_
.c_str (), jacorb
);
1023 ior
+= posjacorb
+ sizeof(jacorb
) - 1;
1027 ior
+= this->server_name_
;
1030 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("%C\n"), ior
.c_str ()));
1032 if (this->filename_
.length () > 0)
1034 FILE *file
= ACE_OS::fopen (this->filename_
.c_str (), "w");
1038 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
1039 ACE_TEXT ("Error: Unable to open %s for writing: %p\n"),
1040 this->filename_
.c_str ()),
1044 ACE_OS::fprintf (file
, "%s", ior
.c_str ());
1045 ACE_OS::fclose (file
);
1048 catch (const CORBA::Exception
& ex
)
1050 ex
._tao_print_exception ("IOR");
1051 return TAO_IMR_Op::UNKNOWN
;
1054 return TAO_IMR_Op::NORMAL
;
1058 TAO_IMR_Op_Kill::run ()
1060 ACE_ASSERT (! CORBA::is_nil(imr_
));
1062 ImplementationRepository::AdministrationExt_var imrext
=
1063 ImplementationRepository::AdministrationExt::_narrow (imr_
);
1064 if (CORBA::is_nil (imrext
.in()))
1066 ORBSVCS_ERROR_RETURN
1068 ACE_TEXT ("Error: requested IMR does not support the kill operation\n")),
1074 imrext
->kill_server (this->server_name_
.c_str(), this->signum_
);
1076 catch (const ImplementationRepository::NotFound
&)
1080 ORBSVCS_ERROR ((LM_ERROR
,
1081 "Could not find server <%C>.\n",
1082 this->server_name_
.c_str ()));
1084 return TAO_IMR_Op::NOT_FOUND
;
1086 catch (const ImplementationRepository::CannotComplete
& ex
)
1090 ORBSVCS_ERROR ((LM_ERROR
,
1091 "Cannot complete kill of <%C> reason <%C>\n",
1092 this->server_name_
.c_str (),
1095 return TAO_IMR_Op::CANNOT_COMPLETE
;
1097 catch (const CORBA::Exception
& ex
)
1099 ex
._tao_print_exception ("Kill");
1100 return TAO_IMR_Op::UNKNOWN
;
1103 return TAO_IMR_Op::NORMAL
;
1107 TAO_IMR_Op_Link::run ()
1109 ACE_ASSERT (! CORBA::is_nil(imr_
));
1111 ImplementationRepository::AdministrationExt_var imrext
=
1112 ImplementationRepository::AdministrationExt::_narrow (imr_
);
1113 if (CORBA::is_nil (imrext
.in()))
1115 ORBSVCS_ERROR_RETURN
1117 ACE_TEXT ("Error: requested IMR does not support the kill operation\n")),
1123 imrext
->link_servers (this->server_name_
.c_str(), this->peers_
);
1125 catch (const ImplementationRepository::NotFound
&)
1127 ORBSVCS_ERROR ((LM_ERROR
,
1128 "Could not find server <%C>.\n",
1129 this->server_name_
.c_str ()));
1130 return TAO_IMR_Op::NOT_FOUND
;
1132 catch (const ImplementationRepository::CannotComplete
& ex
)
1134 ORBSVCS_ERROR ((LM_ERROR
,
1135 "Cannot complete kill of <%C> reason <%C>\n",
1136 this->server_name_
.c_str (),
1138 return TAO_IMR_Op::CANNOT_COMPLETE
;
1140 catch (const CORBA::Exception
& ex
)
1142 ex
._tao_print_exception ("Kill");
1143 return TAO_IMR_Op::UNKNOWN
;
1146 return TAO_IMR_Op::NORMAL
;
1151 TAO_IMR_Op_List::run ()
1153 ACE_ASSERT (! CORBA::is_nil(imr_
));
1155 ImplementationRepository::ServerInformationList_var server_list
;
1156 ImplementationRepository::ServerInformationIterator_var server_iter
;
1160 // If there is a server name, list only that server. Otherwise, look
1162 if (this->server_name_
.length () == 0)
1164 this->imr_
->list (this->how_many_
,
1165 this->list_only_active_servers_
,
1169 if (server_list
->length() == 0)
1171 ORBSVCS_DEBUG((LM_DEBUG
, "No servers found.\n"));
1172 return TAO_IMR_Op::NORMAL
;
1175 for (CORBA::ULong i
= 0; i
< server_list
->length (); i
++)
1176 this->display_server_information (server_list
[i
]);
1178 if (!CORBA::is_nil (server_iter
.in ()))
1180 ORBSVCS_DEBUG ((LM_DEBUG
, "An iterator was returned.\n"));
1181 for (bool done
= false; !done
; )
1183 done
= server_iter
->next_n (this->how_many_
, server_list
.out());
1184 for (CORBA::ULong i
= 0; i
< server_list
->length (); i
++)
1185 this->display_server_information (server_list
[i
]);
1187 server_iter
->destroy ();
1192 ImplementationRepository::ServerInformation_var si
;
1194 this->imr_
->find (this->server_name_
.c_str (), si
);
1195 if (ACE_OS::strlen (si
->server
.in()) > 0)
1197 this->verbose_server_information_
= 1;
1198 this->display_server_information (si
.in ());
1202 throw ImplementationRepository::NotFound ();
1206 catch (const ImplementationRepository::NotFound
&)
1208 ORBSVCS_ERROR ((LM_ERROR
,
1209 "Could not find server <%C>.\n",
1210 this->server_name_
.c_str ()));
1211 return TAO_IMR_Op::NOT_FOUND
;
1213 catch (const CORBA::Exception
& ex
)
1215 ex
._tao_print_exception ("List");
1216 return TAO_IMR_Op::UNKNOWN
;
1219 return TAO_IMR_Op::NORMAL
;
1223 TAO_IMR_Op_Remove::run ()
1225 ACE_ASSERT (! CORBA::is_nil(imr_
));
1231 ImplementationRepository::AdministrationExt_var ext
=
1232 ImplementationRepository::AdministrationExt::_narrow (imr_
);
1233 ACE_ASSERT (! CORBA::is_nil(ext
));
1234 ext
->force_remove_server (this->server_name_
.c_str (),
1239 this->imr_
->remove_server (this->server_name_
.c_str ());
1241 ORBSVCS_DEBUG ((LM_DEBUG
, "Successfully removed server <%C>\n",
1242 this->server_name_
.c_str ()));
1244 catch (const ImplementationRepository::NotFound
&)
1246 ORBSVCS_ERROR ((LM_ERROR
, "Could not find server <%C>.\n",
1247 this->server_name_
.c_str ()));
1248 return TAO_IMR_Op::NOT_FOUND
;
1250 catch (const ImplementationRepository::CannotComplete
& cc
)
1252 ORBSVCS_ERROR ((LM_ERROR
, "Could not complete forced removal of server <%C>. reason: %C\n",
1253 this->server_name_
.c_str (), cc
.reason
.in() ));
1254 return TAO_IMR_Op::CANNOT_COMPLETE
;
1256 catch (const CORBA::NO_PERMISSION
& np
)
1258 if ((np
.minor () & 0x7FU
) == 0xFU
) //TAO_EBUSY_MINOR_CODE)
1260 ORBSVCS_ERROR ((LM_ERROR
, "Server <%C> still busy.\n",
1261 this->server_name_
.c_str ()));
1262 return TAO_IMR_Op::CANNOT_COMPLETE
;
1264 ORBSVCS_ERROR ((LM_ERROR
, "No Permission: ImplRepo is in Locked mode\n"));
1265 return TAO_IMR_Op::NO_PERMISSION
;
1267 catch (const CORBA::Exception
& ex
)
1269 ex
._tao_print_exception ("Removing Server");
1270 return TAO_IMR_Op::UNKNOWN
;
1273 return TAO_IMR_Op::NORMAL
;
1277 TAO_IMR_Op_Shutdown::run ()
1279 ACE_ASSERT (! CORBA::is_nil(imr_
));
1283 this->imr_
->shutdown_server (this->server_name_
.c_str ());
1287 ORBSVCS_DEBUG ((LM_DEBUG
,
1288 "Successfully shut down server <%C>\n",
1289 this->server_name_
.c_str ()));
1292 catch (const ImplementationRepository::NotFound
&)
1296 ORBSVCS_ERROR ((LM_ERROR
,
1297 "Server <%C> already shut down.\n",
1298 this->server_name_
.c_str ()));
1300 return TAO_IMR_Op::NOT_FOUND
;
1302 catch (const CORBA::TIMEOUT
&)
1306 ORBSVCS_DEBUG ((LM_DEBUG
,
1307 "Timeout waiting for <%C> to shutdown.\n",
1308 this->server_name_
.c_str ()));
1311 catch (const CORBA::Exception
& ex
)
1313 ex
._tao_print_exception ("Shutting Down Server");
1314 return TAO_IMR_Op::UNKNOWN
;
1317 return TAO_IMR_Op::NORMAL
;
1321 TAO_IMR_Op_ShutdownRepo::run ()
1323 ACE_ASSERT(! CORBA::is_nil(imr_
));
1327 bool servers
= false; // not implemented yet, if ever
1328 this->imr_
->shutdown (activators_
, servers
);
1330 ORBSVCS_DEBUG ((LM_DEBUG
, "ImR shutdown initiated.\n"));
1332 catch (const CORBA::TIMEOUT
&)
1334 ORBSVCS_DEBUG ((LM_DEBUG
, "Timeout waiting for ImR shutdown.\n"));
1336 catch (const CORBA::Exception
& ex
)
1338 ex
._tao_print_exception ("Shutting Down ImR");
1339 return TAO_IMR_Op::UNKNOWN
;
1342 return TAO_IMR_Op::NORMAL
;
1346 TAO_IMR_Op_Register::run ()
1348 ACE_ASSERT (! CORBA::is_nil(imr_
));
1350 ImplementationRepository::ServerInformation_var server_information
;
1351 ImplementationRepository::StartupOptions local
;
1352 ImplementationRepository::StartupOptions
* options
= 0;
1356 this->imr_
->find (this->server_name_
.c_str (),
1357 server_information
.out ());
1359 if (server_name_
== server_information
->server
.in())
1365 ORBSVCS_DEBUG((LM_DEBUG
,
1366 "(%P|%t) ImR: Server <%C> already registered.\n",
1367 this->server_name_
.c_str ()));
1369 return ALREADY_REGISTERED
;
1371 options
= &server_information
->startup
;
1379 ORBSVCS_DEBUG((LM_DEBUG
,
1380 "(%P|%t) Adding Server <%C> on update command.\n",
1381 this->server_name_
.c_str ()));
1385 local
.activation
= ImplementationRepository::NORMAL
;
1389 if (this->set_command_line_
)
1390 options
->command_line
= CORBA::string_dup (this->command_line_
.c_str ());
1392 if (this->set_environment_vars_
)
1393 options
->environment
= this->environment_vars_
;
1395 if (this->set_working_dir_
)
1396 options
->working_directory
= CORBA::string_dup (this->working_dir_
.c_str ());
1398 if (this->set_activation_
|| is_add_
)
1399 options
->activation
= this->activation_
;
1401 if (this->set_retry_count_
|| is_add_
)
1402 options
->start_limit
= this->retry_count_
+ 1;
1404 if (this->set_activator_
)
1405 options
->activator
= CORBA::string_dup(this->activator_
.c_str ());
1406 // If the command line is set, we must have an activator
1407 else if (this->set_command_line_
&&
1408 (options
->activator
.in () == 0 || *options
->activator
.in () == 0))
1410 char host_name
[MAXHOSTNAMELEN
+ 1];
1411 ACE_OS::hostname (host_name
, MAXHOSTNAMELEN
);
1412 options
->activator
= CORBA::string_dup (host_name
);
1415 ORBSVCS_DEBUG ((LM_DEBUG
,
1416 "(%P|%t) ImR: Updating Server <%C> with default "
1417 "activator of <%C>\n",
1418 this->server_name_
.c_str (),
1419 options
->activator
.in ()));
1422 this->imr_
->add_or_update_server (this->server_name_
.c_str (), *options
);
1426 ORBSVCS_DEBUG((LM_DEBUG
,
1427 "(%P|%t) ImR: Successfully registered <%C>\n",
1428 this->server_name_
.c_str ()));
1431 catch (const CORBA::NO_PERMISSION
&)
1433 ORBSVCS_ERROR ((LM_ERROR
, "(%P|%t) ImR: No Permission: ImplRepo is in Locked mode\n"));
1434 return TAO_IMR_Op::NO_PERMISSION
;
1436 catch (const CORBA::Exception
& ex
)
1438 ex
._tao_print_exception ("Updating server");
1439 return TAO_IMR_Op::UNKNOWN
;
1442 return TAO_IMR_Op::NORMAL
;
1445 // ============================================================================
1446 // = Display Server Information methods
1449 TAO_IMR_Op_List::display_server_information (const ImplementationRepository::ServerInformation
&info
)
1451 const char *maybe
= "";
1452 if (this->list_only_active_servers_
)
1454 switch (info
.activeStatus
)
1456 case ImplementationRepository::ACTIVE_NO
:
1458 case ImplementationRepository::ACTIVE_MAYBE
:
1466 if (this->verbose_server_information_
)
1467 TAO_IMR_Op::display_server_information (info
);
1471 ORBSVCS_DEBUG ((LM_DEBUG
, "%C\n", info
.server
.in ()));
1473 ORBSVCS_DEBUG ((LM_DEBUG
, "<%C> %C\n", info
.server
.in (), maybe
));