summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/RepositoryManager/repository_manager_admin.cpp
blob: 5e5ee24953892bd221764d83f74ae96548ff6ca4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// $Id$
#include "repository_manager_admin.h"
#include "DAnCE/Logger/Log_Macros.h"
#include "RepositoryManagerDaemonC.h"

namespace DAnCE
{
  namespace RepositoryManager
  {
    Admin::Admin (Deployment::RepositoryManager_ptr rm)
      : rm_ (Deployment::RepositoryManager::_duplicate (rm))
    {
      DANCE_TRACE ("Admin::Admin");
    }


    /// Install a package at a provided filesystem path.
    bool
    Admin::install_package (const ACE_TCHAR *uri,
                            const ACE_TCHAR *name,
                            bool replace)
    {
      DANCE_TRACE ("Admin::install_package");

      try
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO "Admin::install_package - "
                        "Installing package with URI: %s, name: %s\n",
                        uri, name));
          this->rm_->installPackage (ACE_TEXT_ALWAYS_CHAR (name),
                                     ACE_TEXT_ALWAYS_CHAR (uri),
                                     replace);
          DANCE_DEBUG (9, (LM_TRACE, DLINFO "Admin::install_package - "
                        "Package installed successfully\n"));
        }
      catch (Deployment::NameExists &)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::install_package - "
                        "Package with name %s already installed.\n",
                        name));
          return false;
        }
      catch (Deployment::PackageError &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::install_package - "
                        "Internal error while installing package with name %s: %C - %C\n",
                        name, ex.source.in (), ex.reason.in ()));
          return false;
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::install_package - "
                        "Unexpected CORBA Exception while installing package with name: %s.  Reason: %C\n",
                        name,
                        ex._info ().c_str ()));
          return false;
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::install_package - "
                        "Unexpected C++ exception while installing package with name: %s\n",
                        name));
          return false;
        }

      return true;
    }

    /// Create new package.
    bool
    Admin::create_package (const ACE_TCHAR * /* pc_path */,
                           const ACE_TCHAR * /** name*/,
                           const ACE_TCHAR * /*baselocation*/,
                           bool  /*replace*/)
    {
      DANCE_TRACE ("Admin::create_package");

      return false;
    }

    /// Uninstall a package with a provided UUID.
    /// Fails if the NoSuchName exception was raised.
    bool
    Admin::uninstall_package (const ACE_TCHAR *uuid)
    {
      DANCE_TRACE ("Admin::uninstall_package");

      try
        {
          DANCE_DEBUG (9, (LM_TRACE, DLINFO "Admin::uninstall_package - "
                        "Attempting to uninstall package %s\n",
                        uuid));
          this->rm_->deletePackage (ACE_TEXT_ALWAYS_CHAR (uuid));
          DANCE_DEBUG (8, (LM_INFO, DLINFO "Admin::uninstall_package - "
                        "Successfully uninstalled package %s\n",
                        uuid));
        }
      catch (Deployment::NoSuchName &)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::uninstall_package - "
                        "No package with the given UUID found: %s\n",
                        uuid));
          return false;
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::uninstall_package - "
                        "Unexpected CORBA Exception while uninstalling package with uuid: %s. Reason: %C\n",
                        uuid,
                        ex._info ().c_str ()));
          return false;
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::uninstall_package - "
                        "Unexpected C++ exception while installing package with uuid: %C\n",
                        uuid));
          return false;
        }

      return true;
    }

    /// List all installed packages
    ::CORBA::StringSeq *
    Admin::list_packages (void)
    {
      DANCE_TRACE ("Admin::list_packages");

      try
        {
          CORBA::StringSeq_var packages = this->rm_->getAllNames ();
          return packages._retn ();
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::list_packages - "
                        "Unexpected CORBA Exception while listing packages: %C\n",
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::list_package - "
                        "Unexpected C++ exception while listing packages\n"));
          return 0;
        }

      return 0;
    }

    /// List all installed package types
    ::CORBA::StringSeq *
    Admin::list_types (void)
    {
      DANCE_TRACE ("Admin::list_types");

      try
        {
          CORBA::StringSeq_var packages = this->rm_->getAllTypes ();
          return packages._retn ();
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::list_types - "
                        "Unexpected CORBA Exception while listing package types: %C\n",
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::list_types - "
                        "Unexpected C++ exception while listing package types\n"));
          return 0;
        }

      return 0;
    }

    /// Find package names by type
    ::CORBA::StringSeq *
    Admin::find_by_type (const ACE_TCHAR *type)
    {
      DANCE_TRACE ("Admin::find_by_type");

      if (type == 0)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::find_by_type - "
                        "Nill type passed to find_by_type\n"));
          return 0;
        }

      try
        {
          ::CORBA::StringSeq_var types = this->rm_->findNamesByType (ACE_TEXT_ALWAYS_CHAR (type));
          types._retn ();
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::find_by_type - "
                        "Unexpected CORBA Exception while listing packages of type %C: %C\n",
                        type,
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::find_by_type - "
                        "Unexpected C++ exception while listing packages by type %C\n",
                        type));
          return 0;
        }

      return 0;
    }

    /// Attempt to shutdown the server.
    bool
    Admin::shutdown (void)
    {
      DANCE_TRACE ("Admin::shutdown");

      DANCE_DEBUG (9, (LM_TRACE, DLINFO "Admin::shutdown - "
                    "Attempting to shut down Repository Manager\n"));
      CIAO::RepositoryManagerDaemon_var rmd =
        CIAO::RepositoryManagerDaemon::_narrow (this->rm_.in ());
      DANCE_DEBUG (8, (LM_INFO, DLINFO "Admin::shutdown - "
                    "Repository Manager shut down.\n"));
      if (CORBA::is_nil (rmd.in ()))
        {
          DANCE_ERROR (1, (LM_ERROR, DLINFO "Admin::shutdown - "
                        "Unable to narrow provided RM reference to a CIAO::RepositoryManagerDaemon\n"));
          return false;
        }

      rmd->shutdown ();

      return true;
    }
  }
}