~ubuntu-branches/debian/sid/opennebula/sid

« back to all changes in this revision

Viewing changes to src/rm/RequestManagerCluster.cc

  • Committer: Package Import Robot
  • Author(s): Damien Raude-Morvan
  • Date: 2012-05-11 19:27:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120511192743-lnz8gog5uxzmx2f3
Tags: 3.4.1-1
* New upstream release:
  - d/patches/default_conf.diff: Drop, transfert manager is now handled
    on a datasatore basis.
  - d/patches/genisoimage.diff: Merged upstream.
  - d/patches/oneacct-system-wide-installation.patch: Merged upstream.
  - Refresh others patches.
  - Update *.install files.
* Improve OCCI Self-Service UI integration:
  - Install into /usr/share/opennebula/occi/.
  - occi_system_jquery.diff: Use system wide jquery/jqueryui.
  - Add Recommends: libjs-jquery, libjs-jquery-ui for opennebula package.
* Add Suggests: ruby-uuidtools for econe-server.
* Install more manpages from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -------------------------------------------------------------------------- */
 
2
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)             */
 
3
/*                                                                            */
 
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
 
5
/* not use this file except in compliance with the License. You may obtain    */
 
6
/* a copy of the License at                                                   */
 
7
/*                                                                            */
 
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
 
9
/*                                                                            */
 
10
/* Unless required by applicable law or agreed to in writing, software        */
 
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
 
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
 
13
/* See the License for the specific language governing permissions and        */
 
14
/* limitations under the License.                                             */
 
15
/* -------------------------------------------------------------------------- */
 
16
 
 
17
#include "RequestManagerCluster.h"
 
18
 
 
19
using namespace std;
 
20
 
 
21
/* ------------------------------------------------------------------------- */
 
22
/* ------------------------------------------------------------------------- */
 
23
 
 
24
void RequestManagerCluster::add_generic(
 
25
        int                         cluster_id,
 
26
        int                         object_id,
 
27
        RequestAttributes&          att,
 
28
        PoolSQL *                   pool,
 
29
        PoolObjectSQL::ObjectType   type)
 
30
{
 
31
    int rc;
 
32
 
 
33
    string cluster_name;
 
34
    string obj_name;
 
35
    string err_msg;
 
36
 
 
37
    Cluster *       cluster;
 
38
    Clusterable *   cluster_obj = 0;
 
39
    PoolObjectSQL * object = 0;
 
40
 
 
41
 
 
42
    PoolObjectAuth c_perms;
 
43
    PoolObjectAuth obj_perms;
 
44
 
 
45
    int     old_cluster_id;
 
46
    string  old_cluster_name;
 
47
 
 
48
    if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
 
49
    {
 
50
        rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, cluster_name);
 
51
 
 
52
        if ( rc == -1 )
 
53
        {
 
54
            return;
 
55
        }
 
56
    }
 
57
    else
 
58
    {
 
59
        cluster_name = ClusterPool::NONE_CLUSTER_NAME;
 
60
    }
 
61
 
 
62
    rc = get_info(pool, object_id, type, att, obj_perms, obj_name);
 
63
 
 
64
    if ( rc == -1 )
 
65
    {
 
66
        return;
 
67
    }
 
68
 
 
69
    if ( att.uid != 0 )
 
70
    {
 
71
        AuthRequest ar(att.uid, att.gid);
 
72
 
 
73
        if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
 
74
        {
 
75
            ar.add_auth(auth_op, c_perms);          // ADMIN  CLUSTER
 
76
        }
 
77
 
 
78
        ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN  OBJECT
 
79
 
 
80
        if (UserPool::authorize(ar) == -1)
 
81
        {
 
82
            failure_response(AUTHORIZATION,
 
83
                             authorization_error(ar.message, att),
 
84
                             att);
 
85
 
 
86
            return;
 
87
        }
 
88
    }
 
89
 
 
90
    // ------------- Set new cluster id in object ---------------------
 
91
    get(object_id, true, &object, &cluster_obj);
 
92
 
 
93
    if ( object == 0 )
 
94
    {
 
95
        failure_response(NO_EXISTS,
 
96
                get_error(object_name(type), object_id),
 
97
                att);
 
98
 
 
99
        return;
 
100
    }
 
101
 
 
102
    old_cluster_id   = cluster_obj->get_cluster_id();
 
103
    old_cluster_name = cluster_obj->get_cluster_name();
 
104
 
 
105
    if ( old_cluster_id == cluster_id )
 
106
    {
 
107
        object->unlock();
 
108
        success_response(cluster_id, att);
 
109
        return;
 
110
    }
 
111
 
 
112
    cluster_obj->set_cluster(cluster_id, cluster_name);
 
113
 
 
114
    pool->update(object);
 
115
 
 
116
    object->unlock();
 
117
 
 
118
    // ------------- Add object to new cluster ---------------------
 
119
    if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
 
120
    {
 
121
        cluster = clpool->get(cluster_id, true);
 
122
 
 
123
        if ( cluster == 0 )
 
124
        {
 
125
            failure_response(NO_EXISTS,
 
126
                    get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id),
 
127
                    att);
 
128
 
 
129
            // Rollback
 
130
            get(object_id, true, &object, &cluster_obj);
 
131
 
 
132
            if ( object != 0 )
 
133
            {
 
134
                cluster_obj->set_cluster(old_cluster_id, old_cluster_name);
 
135
 
 
136
                pool->update(object);
 
137
 
 
138
                object->unlock();
 
139
            }
 
140
 
 
141
            return;
 
142
        }
 
143
 
 
144
        if ( add_object(cluster, object_id, err_msg) < 0 )
 
145
        {
 
146
            cluster->unlock();
 
147
 
 
148
            failure_response(INTERNAL,
 
149
                    request_error("Cannot add object to cluster", err_msg),
 
150
                    att);
 
151
 
 
152
            return;
 
153
        }
 
154
 
 
155
        clpool->update(cluster);
 
156
 
 
157
        cluster->unlock();
 
158
    }
 
159
 
 
160
    // ------------- Remove host from old cluster ---------------------
 
161
 
 
162
    if ( old_cluster_id != ClusterPool::NONE_CLUSTER_ID )
 
163
    {
 
164
        cluster = clpool->get(old_cluster_id, true);
 
165
 
 
166
        if ( cluster == 0 )
 
167
        {
 
168
            // This point should be unreachable.
 
169
            // The old cluster is not empty (at least has the host_id),
 
170
            // so it cannot be deleted
 
171
            success_response(cluster_id, att);
 
172
            return;
 
173
        }
 
174
 
 
175
        if ( del_object(cluster, object_id, err_msg) < 0 )
 
176
        {
 
177
            cluster->unlock();
 
178
 
 
179
            failure_response(INTERNAL,
 
180
                    request_error("Cannot remove object from cluster", err_msg),
 
181
                    att);
 
182
 
 
183
            return;
 
184
        }
 
185
 
 
186
        clpool->update(cluster);
 
187
 
 
188
        cluster->unlock();
 
189
    }
 
190
 
 
191
    success_response(cluster_id, att);
 
192
 
 
193
    return;
 
194
}