summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DAnCE/RepositoryManager/Update_Plan.cpp
blob: f8f16019b9504535d3f77330270cd84e3409c2d6 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// $Id$

#include "RepositoryManager_Impl.h"
#include "Update_Plan.h"
#include "DeploymentC.h"
#include "ace/Hash_Map_Manager.h"
#include "ace/OS_NS_stdio.h"
#include "ace/streams.h"

ACE_RCSID (DAnCE,
           RepositoryManager,
           "$Id$")

using namespace Deployment;

namespace CIAO
{
  void
  traverse_package (PackageConfiguration* &pc,
                    DeploymentPlan &plan,
                    REF_MAP &ref_map,
                    REF_MAP &primary_ref_map)
  {
    // traverse the package configuration structure to get to the
    // BasePackage which consists of assemblies.
    //
    CORBA::ULong bp_len =
      pc->basePackage.length ();

    for (CORBA::ULong x = 0; x != bp_len; ++x)
      {
        CORBA::ULong impl_len =
          pc->basePackage[x].implementation.length ();

        for (CORBA::ULong y = 0;
             y != impl_len;
             ++y)
          {
            // traverse the .cpd file and get to the referenced .cid file
            //
            ComponentImplementationDescription cid =
              pc->basePackage[x].implementation[y].referencedImplementation;
            CORBA::ULong assembly_len = cid.assemblyImpl.length ();

            for (CORBA::ULong z = 0;
                 z != assembly_len;
                 ++z)
              {
                // traverse the .cid file and get to each
                // of the "assemblyImpl" tags.
                //
                ComponentAssemblyDescription assembly =
                  cid.assemblyImpl[z];
                //
                // traverse the individual assembly.
                //
                traverse_assembly (assembly, plan, ref_map, primary_ref_map);
              }
          }
      }
  }

  void
  traverse_assembly (ComponentAssemblyDescription &assembly,
                     DeploymentPlan &plan,
                     REF_MAP &ref_map, REF_MAP &primary_ref_map)
  {
    // traverse the assembly (ComponentAssemblyDescription) and
    // processes the instances and the connection within the assembly.
    //
    CORBA::ULong ins_len = assembly.instance.length ();
    for (CORBA::ULong k = 0; k < ins_len; ++k)
      {
        SubcomponentInstantiationDescription ins =
          assembly.instance[k];
        const char* in_name = ins.name;

      CORBA::ULong plan_ins_len =
        plan.instance.length ();

      for (CORBA::ULong l = 0; l < plan_ins_len; ++l)
        {
          const char* plan_name = plan.instance[l].name;
          if (strcmp (plan_name, in_name) == 0)
            {
              traverse_assembly_instance (ins, plan, l,
                                          ref_map, primary_ref_map);
            }
        }
      }

    CORBA::ULong assembly_conn_len =
      assembly.connection.length ();

    for (CORBA::ULong m = 0; m < assembly_conn_len; ++m)
      {
        AssemblyConnectionDescription
          assembly_connection = assembly.connection[m];
        traverse_assembly_connection (assembly,
                                      assembly_connection,
                                      plan);
      }
  }

  void
  traverse_assembly_connection (ComponentAssemblyDescription
                                &assembly,
                                AssemblyConnectionDescription
                                &assembly_connection,
                                DeploymentPlan &plan)
  {
    // traverse the assembly connection and get information about the
    // portName and the instances at each end of the connection.
    // Also traverse the InterfaceDescriptions for each of those instances
    // and populate the portKind information.
    //
    CORBA::ULong con_length (plan.connection.length ());
    plan.connection.length (con_length + 1);
    CORBA::ULong iepe_len = assembly_connection.internalEndpoint.length ();
    for (CORBA::ULong n = 0; n < iepe_len; ++n)
      {
        CORBA::ULong iep_len (plan.connection[con_length].
                              internalEndpoint.length ());
      plan.connection[con_length].internalEndpoint
        .length (iep_len + 1);
      plan.connection[con_length].internalEndpoint
        [iep_len].portName = assembly_connection.
        internalEndpoint[n].portName;
      CORBA::ULong ins_ref = assembly_connection.internalEndpoint[n].
        instanceRef;
      const char* ins_name = assembly.instance[ins_ref].name;
      CORBA::ULong plan_ins_len = plan.instance.length ();
      for (CORBA::ULong w = 0; w < plan_ins_len; ++w)
        {
          const char* pl_name = plan.instance[w].name;
          if (strcmp (pl_name, ins_name) == 0)
            {
              plan.connection[con_length].internalEndpoint
                [iep_len].instanceRef = w;
              break;
            }
        }
      traverse_interface (assembly.instance[ins_ref],
                          plan.connection[con_length].
                          internalEndpoint[iep_len]);
      }
  }

  void
  traverse_interface (SubcomponentInstantiationDescription
                      &instance,
                      PlanSubcomponentPortEndpoint
                      &pspe)
  {
    // traverse the InterfaceDescription of the instance and get information
    // about the portkind of the port.
    //
    CORBA::ULong pack_len = instance.package.length ();
    for (CORBA::ULong m = 0; m < pack_len; ++m)
      {
        ComponentPackageDescription
          package = instance.package[m];

        ComponentInterfaceDescription
          cid = package.realizes;

        CORBA::ULong port_len = cid.port.length ();

        for (CORBA::ULong n = 0; n < port_len; ++n)
          {
            const char* main_port_name = cid.port[n].name;
            const char* port_name = pspe.portName;
            if (strcmp (main_port_name, port_name) == 0)
              {
                pspe.kind = cid.port[n].kind;
              }
          }
      }
  }

  void
  traverse_assembly_instance (
                              SubcomponentInstantiationDescription
                              &instance,
                              DeploymentPlan &plan, int l,
                              REF_MAP &ref_map, REF_MAP &primary_ref_map)
  {
    // Each instance has a package.
    //   Each package has an implementation and their correspoding artifacts.
    // Traverse this information and populate the artifact and the
    // implementation information within the DeploymentPlan.
    //
    ART_REF_MAP art_ref_map;

    CORBA::ULong pack_len = instance.package.length ();

    for (CORBA::ULong m = 0; m < pack_len; ++m)
      {
        ComponentPackageDescription
          package = instance.package[m];
        CORBA::ULong pack_impl_len = package.implementation.length ();

        for (CORBA::ULong n = 0; n < pack_impl_len; ++n)
          {
            PackagedComponentImplementation
              impl = package.implementation[n];
            CORBA::ULong impl_length (plan.implementation.length ());
            plan.implementation.length (impl_length + 1);
            plan.implementation[impl_length].name = plan.instance[l].name;
            plan.instance[l].implementationRef = impl_length;
            CORBA::ULong mono_impl_len =
              impl.referencedImplementation.monolithicImpl.length ();

            for (CORBA::ULong p = 0; p < mono_impl_len; ++p)
              {
                MonolithicImplementationDescription
                  mid = impl.referencedImplementation.monolithicImpl[p];

                update_artifacts (mid, plan, plan.instance[l],
                                ref_map, primary_ref_map, art_ref_map,
                                  plan.implementation[impl_length]);
              }
            update_impl_config_property (impl, plan.implementation[impl_length],
                                         plan.instance[l]);
          }
      }
  }

  void
  update_artifacts (MonolithicImplementationDescription &mid,
                    DeploymentPlan &plan,
                    InstanceDeploymentDescription &instance,
                    REF_MAP &ref_map, REF_MAP &primary_ref_map,
                    ART_REF_MAP &art_ref_map,
                    MonolithicDeploymentDescription &mdd)
  {
    CORBA::ULong prim_art_len = mid.primaryArtifact.length ();
    for (CORBA::ULong q = 0; q < prim_art_len; ++q)
      {
        ImplementationArtifactDescription
          pack_iad = mid.primaryArtifact[q].referencedArtifact;
        ACE_TString artifact_name = (const char*)mid.primaryArtifact[q].name;
        int arti_len;
        CORBA::ULong art_length (plan.artifact.length ());

        if (ref_map.find (artifact_name, arti_len) != 0)
          {
            plan.artifact.length (art_length + 1);
            plan.artifact[art_length].name = mid.primaryArtifact[q].name;
            plan.artifact[art_length].node = instance.node;
            ref_map.bind (artifact_name, art_length);
            primary_ref_map.bind (artifact_name, art_length);
            CORBA::ULong art_ref_len (mdd.artifactRef.length ());
            mdd.artifactRef.length (art_ref_len + 1);
            mdd.artifactRef[art_ref_len] = art_length;
            update_artifact_location (pack_iad,
                                    plan.artifact[art_length]);
            update_artifact_property (pack_iad,
                                      plan.artifact[art_length]);
          }
        update_common_artifact_and_art_ref (pack_iad,
                                            primary_ref_map, ref_map,
                                          art_ref_map, mdd,
                                            plan, instance);
      }
  }

  void
  update_common_artifact_and_art_ref (
                                      ImplementationArtifactDescription
                                      &pack_iad,
                                      REF_MAP &primary_ref_map,
                                      REF_MAP &ref_map,
                                      ART_REF_MAP &art_ref_map,

                                      MonolithicDeploymentDescription &mid,
                                      DeploymentPlan &plan,

                                         InstanceDeploymentDescription
                                         &instance)
  {
    CORBA::ULong deps_len = pack_iad.dependsOn.length ();
    for (CORBA::ULong g = 0; g < deps_len; ++g)
      {
        ACE_TString dep_name =
          (const char*)pack_iad.dependsOn[g].name;
        int arti_len;

        if (ref_map.find (dep_name, arti_len) == 0)
          {
            if (primary_ref_map.find (dep_name, arti_len) != 0)
              {
                if (art_ref_map.find (arti_len, arti_len) != 0)
                  {
                    update_impl_art_ref (mid, arti_len);
                    art_ref_map.bind (arti_len, arti_len);
                  }
              }
          }
        else
          {
            ImplementationArtifactDescription
              depends_iad = pack_iad.dependsOn[g].
              referencedArtifact;
            CORBA::ULong new_art_length (plan.artifact.length ());
            plan.artifact.length (new_art_length + 1);
            plan.artifact[new_art_length].name =
              pack_iad.dependsOn[g].name;
            plan.artifact[new_art_length].node = instance.node;
            update_artifact_location (depends_iad,
                                      plan.artifact
                                      [new_art_length]);
            ref_map.bind (
                          (const char*)plan.artifact[new_art_length].name,
                          new_art_length);
            update_impl_art_ref (mid, new_art_length);
            art_ref_map.bind (new_art_length, new_art_length);
          }
      }
  }

  void
  update_impl_config_property (PackagedComponentImplementation
                               &impl,
                               MonolithicDeploymentDescription
                               &mid,

                                  InstanceDeploymentDescription
                               &instance)
  {
    CORBA::ULong pro_len =
    impl.referencedImplementation.configProperty.length ();

    for (CORBA::ULong x = 0; x < pro_len; ++x)
      {
        CORBA::ULong impl_pro_len (mid.execParameter.length ());
        mid.execParameter.length (impl_pro_len + 1);
        mid.execParameter[impl_pro_len]
          = impl.referencedImplementation.configProperty[x];
        CORBA::ULong ins_pro_len (instance.configProperty. length ());
        instance.configProperty.length (ins_pro_len + 1);
        instance.configProperty[ins_pro_len]
          = impl.referencedImplementation.configProperty[x];
      }
  }

  void
  update_impl_art_ref (MonolithicDeploymentDescription &mid,
                       int arti_len)
  {
    CORBA::ULong new_art_ref_len (mid.artifactRef.length ());
    mid.artifactRef.length (new_art_ref_len + 1);
    mid.artifactRef[new_art_ref_len] = arti_len;
  }

  void
  update_artifact_location (ImplementationArtifactDescription
                            &pack_iad,
                            ArtifactDeploymentDescription
                            &plan_artifact)
  {
    CORBA::ULong loc_len = pack_iad.location.length ();
    for (CORBA::ULong e = 0; e < loc_len; ++e)
      {
        CORBA::ULong art_loc_len (plan_artifact.location.length ());
        plan_artifact.location.length (art_loc_len + 1);
        plan_artifact.location[art_loc_len] = pack_iad.location[e];
      }
  }

  void
  update_artifact_property (ImplementationArtifactDescription
                            &pack_iad,
                            ArtifactDeploymentDescription
                            &plan_artifact)
  {
    CORBA::ULong para_len = pack_iad.execParameter.length ();
    for (CORBA::ULong f = 0; f < para_len; ++f)
      {
        CORBA::ULong art_pro_len (plan_artifact.execParameter.length ());
        plan_artifact.execParameter.length (art_pro_len + 1);
        plan_artifact.execParameter[art_pro_len] = pack_iad.execParameter[f];
      }
  }
}