summaryrefslogtreecommitdiff
path: root/DAnCE/dance/RepositoryManager/repository_manager_admin.cpp
blob: 754880c72406267dbf5215538c41c0e5dbad20f0 (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
242
243
244
245
246
247
#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 (DANCE_LOG_MAJOR_EVENT,
                       (LM_TRACE, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("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 (DANCE_LOG_EVENT_TRACE,
                       (LM_TRACE, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("Package installed successfully\n")));
        }
      catch (Deployment::NameExists &)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("Package with name %s already installed.\n"),
                        name));
          return false;
        }
      catch (Deployment::PackageError &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("Internal error while installing package with name %s: %C - %C\n"),
                        name, ex.source.in (), ex.reason.in ()));
          return false;
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("Unexpected CORBA Exception while installing package with name: %s.  Reason: %C\n"),
                        name,
                        ex._info ().c_str ()));
          return false;
        }
      catch (...)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::install_package - ")
                        ACE_TEXT ("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 (DANCE_LOG_MAJOR_EVENT,
                       (LM_TRACE, DLINFO ACE_TEXT ("Admin::uninstall_package - ")
                        ACE_TEXT ("Attempting to uninstall package %s\n"),
                        uuid));
          this->rm_->deletePackage (ACE_TEXT_ALWAYS_CHAR (uuid));
          DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
                       (LM_INFO, DLINFO ACE_TEXT ("Admin::uninstall_package - ")
                        ACE_TEXT ("Successfully uninstalled package %s\n"),
                        uuid));
        }
      catch (Deployment::NoSuchName &)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::uninstall_package - ")
                        ACE_TEXT ("No package with the given UUID found: %s\n"),
                        uuid));
          return false;
        }
      catch (const CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::uninstall_package - ")
                        ACE_TEXT ("Unexpected CORBA Exception while uninstalling package with uuid: %s. Reason: %C\n"),
                        uuid,
                        ex._info ().c_str ()));
          return false;
        }
      catch (...)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::uninstall_package - ")
                        ACE_TEXT ("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 (const CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::list_packages - ")
                        ACE_TEXT ("Unexpected CORBA Exception while listing packages: %C\n"),
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::list_package - ")
                        ACE_TEXT ("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 (const CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::list_types - ")
                        ACE_TEXT ("Unexpected CORBA Exception while listing package types: %C\n"),
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::list_types - ")
                        ACE_TEXT ("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 (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::find_by_type - ")
                                         ACE_TEXT ("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 (const CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::find_by_type - ")
                        ACE_TEXT ("Unexpected CORBA Exception while listing packages of type %C: %C\n"),
                        type,
                        ex._info ().c_str ()));
          return 0;
        }
      catch (...)
        {
          DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Admin::find_by_type - ")
                        ACE_TEXT ("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 (DANCE_LOG_MAJOR_EVENT,
                   (LM_TRACE, DLINFO ACE_TEXT ("Admin::shutdown - ")
                    ACE_TEXT ("Attempting to shut down Repository Manager\n")));
      CIAO::RepositoryManagerDaemon_var rmd =
        CIAO::RepositoryManagerDaemon::_narrow (this->rm_.in ());
      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
                   (LM_INFO, DLINFO ACE_TEXT ("Admin::shutdown - ")
                    ACE_TEXT ("Repository Manager shut down.\n")));
      if (CORBA::is_nil (rmd.in ()))
        {
          DANCE_ERROR (DANCE_LOG_ERROR,
                       (LM_ERROR, DLINFO ACE_TEXT ("Admin::shutdown - ")
                        ACE_TEXT ("Unable to narrow provided RM reference to a CIAO::RepositoryManagerDaemon\n")));
          return false;
        }

      rmd->shutdown ();

      return true;
    }
  }
}